mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-19 02:24:40 +02:00
8168792: [AOT] problems in MethodHandle with aot-compiled java.base
Properly support assertions in AOT Reviewed-by: kvn
This commit is contained in:
parent
9b98f88304
commit
2d444d6f19
6 changed files with 66 additions and 40 deletions
|
@ -37,6 +37,7 @@ import jdk.tools.jaotc.binformat.Symbol.Binding;
|
||||||
import jdk.tools.jaotc.binformat.Symbol.Kind;
|
import jdk.tools.jaotc.binformat.Symbol.Kind;
|
||||||
import jdk.tools.jaotc.binformat.elf.JELFRelocObject;
|
import jdk.tools.jaotc.binformat.elf.JELFRelocObject;
|
||||||
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
|
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
|
||||||
|
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A format-agnostic container class that holds various components of a binary.
|
* A format-agnostic container class that holds various components of a binary.
|
||||||
|
@ -257,9 +258,9 @@ public class BinaryContainer implements SymbolTable {
|
||||||
* prefix {@code prefix}. It also initializes internal code container, symbol table and
|
* prefix {@code prefix}. It also initializes internal code container, symbol table and
|
||||||
* relocation tables.
|
* relocation tables.
|
||||||
*/
|
*/
|
||||||
public BinaryContainer(GraalHotSpotVMConfig config, String jvmVersion) {
|
public BinaryContainer(GraalHotSpotVMConfig graalHotSpotVMConfig, GraphBuilderConfiguration graphBuilderConfig, String jvmVersion) {
|
||||||
this.codeSegmentSize = config.codeSegmentSize;
|
this.codeSegmentSize = graalHotSpotVMConfig.codeSegmentSize;
|
||||||
this.codeEntryAlignment = config.codeEntryAlignment;
|
this.codeEntryAlignment = graalHotSpotVMConfig.codeEntryAlignment;
|
||||||
|
|
||||||
// read only, code
|
// read only, code
|
||||||
codeContainer = new CodeContainer(".text", this);
|
codeContainer = new CodeContainer(".text", this);
|
||||||
|
@ -289,30 +290,31 @@ public class BinaryContainer implements SymbolTable {
|
||||||
|
|
||||||
addGlobalSymbols();
|
addGlobalSymbols();
|
||||||
|
|
||||||
recordConfiguration(config);
|
recordConfiguration(graalHotSpotVMConfig, graphBuilderConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void recordConfiguration(GraalHotSpotVMConfig config) {
|
private void recordConfiguration(GraalHotSpotVMConfig graalHotSpotVMConfig, GraphBuilderConfiguration graphBuilderConfig) {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
boolean[] booleanFlags = { config.cAssertions, // Debug VM
|
boolean[] booleanFlags = { graalHotSpotVMConfig.cAssertions, // Debug VM
|
||||||
config.useCompressedOops,
|
graalHotSpotVMConfig.useCompressedOops,
|
||||||
config.useCompressedClassPointers,
|
graalHotSpotVMConfig.useCompressedClassPointers,
|
||||||
config.compactFields,
|
graalHotSpotVMConfig.compactFields,
|
||||||
config.useG1GC,
|
graalHotSpotVMConfig.useG1GC,
|
||||||
config.useCMSGC,
|
graalHotSpotVMConfig.useCMSGC,
|
||||||
config.useTLAB,
|
graalHotSpotVMConfig.useTLAB,
|
||||||
config.useBiasedLocking,
|
graalHotSpotVMConfig.useBiasedLocking,
|
||||||
TieredAOT.getValue(),
|
TieredAOT.getValue(),
|
||||||
config.enableContended,
|
graalHotSpotVMConfig.enableContended,
|
||||||
config.restrictContended,
|
graalHotSpotVMConfig.restrictContended,
|
||||||
|
graphBuilderConfig.omitAssertions()
|
||||||
};
|
};
|
||||||
|
|
||||||
int[] intFlags = { config.narrowOopShift,
|
int[] intFlags = { graalHotSpotVMConfig.narrowOopShift,
|
||||||
config.narrowKlassShift,
|
graalHotSpotVMConfig.narrowKlassShift,
|
||||||
config.contendedPaddingWidth,
|
graalHotSpotVMConfig.contendedPaddingWidth,
|
||||||
config.fieldsAllocationStyle,
|
graalHotSpotVMConfig.fieldsAllocationStyle,
|
||||||
config.objectAlignment,
|
graalHotSpotVMConfig.objectAlignment,
|
||||||
config.codeSegmentSize,
|
graalHotSpotVMConfig.codeSegmentSize,
|
||||||
};
|
};
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
|
||||||
|
|
|
@ -77,10 +77,14 @@ public class AOTBackend {
|
||||||
this.filters = filters;
|
this.filters = filters;
|
||||||
providers = backend.getProviders();
|
providers = backend.getProviders();
|
||||||
codeCache = providers.getCodeCache();
|
codeCache = providers.getCodeCache();
|
||||||
graphBuilderSuite = initGraphBuilderSuite(backend);
|
graphBuilderSuite = initGraphBuilderSuite(backend, main.options.compileWithAssertions);
|
||||||
highTierContext = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.ALL);
|
highTierContext = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PhaseSuite<HighTierContext> getGraphBuilderSuite() {
|
||||||
|
return graphBuilderSuite;
|
||||||
|
}
|
||||||
|
|
||||||
private Suites getSuites() {
|
private Suites getSuites() {
|
||||||
// create suites every time, as we modify options for the compiler
|
// create suites every time, as we modify options for the compiler
|
||||||
return backend.getSuites().getDefaultSuites();
|
return backend.getSuites().getDefaultSuites();
|
||||||
|
@ -146,14 +150,14 @@ public class AOTBackend {
|
||||||
return backend.getRuntime().getVMConfig().cAssertions;
|
return backend.getRuntime().getVMConfig().cAssertions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PhaseSuite<HighTierContext> initGraphBuilderSuite(HotSpotBackend backend) {
|
private static PhaseSuite<HighTierContext> initGraphBuilderSuite(HotSpotBackend backend, boolean compileWithAssertions) {
|
||||||
PhaseSuite<HighTierContext> graphBuilderSuite = backend.getSuites().getDefaultGraphBuilderSuite().copy();
|
PhaseSuite<HighTierContext> graphBuilderSuite = backend.getSuites().getDefaultGraphBuilderSuite().copy();
|
||||||
ListIterator<BasePhase<? super HighTierContext>> iterator = graphBuilderSuite.findPhase(GraphBuilderPhase.class);
|
ListIterator<BasePhase<? super HighTierContext>> iterator = graphBuilderSuite.findPhase(GraphBuilderPhase.class);
|
||||||
GraphBuilderConfiguration baseConfig = ((GraphBuilderPhase) iterator.previous()).getGraphBuilderConfig();
|
GraphBuilderConfiguration baseConfig = ((GraphBuilderPhase) iterator.previous()).getGraphBuilderConfig();
|
||||||
|
|
||||||
// Use all default plugins.
|
// Use all default plugins.
|
||||||
Plugins plugins = baseConfig.getPlugins();
|
Plugins plugins = baseConfig.getPlugins();
|
||||||
GraphBuilderConfiguration aotConfig = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
|
GraphBuilderConfiguration aotConfig = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withOmitAssertions(!compileWithAssertions);
|
||||||
|
|
||||||
iterator.next();
|
iterator.next();
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
|
|
|
@ -45,6 +45,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@ -54,8 +55,14 @@ import jdk.tools.jaotc.collect.ClassCollector;
|
||||||
import jdk.tools.jaotc.utils.Timer;
|
import jdk.tools.jaotc.utils.Timer;
|
||||||
|
|
||||||
import org.graalvm.compiler.api.runtime.GraalJVMCICompiler;
|
import org.graalvm.compiler.api.runtime.GraalJVMCICompiler;
|
||||||
|
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
|
||||||
import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
|
import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
|
||||||
import org.graalvm.compiler.hotspot.HotSpotHostBackend;
|
import org.graalvm.compiler.hotspot.HotSpotHostBackend;
|
||||||
|
import org.graalvm.compiler.java.GraphBuilderPhase;
|
||||||
|
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
|
||||||
|
import org.graalvm.compiler.phases.BasePhase;
|
||||||
|
import org.graalvm.compiler.phases.PhaseSuite;
|
||||||
|
import org.graalvm.compiler.phases.tiers.HighTierContext;
|
||||||
import org.graalvm.compiler.runtime.RuntimeProvider;
|
import org.graalvm.compiler.runtime.RuntimeProvider;
|
||||||
|
|
||||||
import jdk.vm.ci.meta.MetaAccessProvider;
|
import jdk.vm.ci.meta.MetaAccessProvider;
|
||||||
|
@ -144,11 +151,16 @@ public class Main implements LogPrinter {
|
||||||
void process(Main task, String opt, String arg) {
|
void process(Main task, String opt, String arg) {
|
||||||
task.options.methodList = arg;
|
task.options.methodList = arg;
|
||||||
}
|
}
|
||||||
}, new Option(" --compile-for-tiered Generated profiling code for tiered compilation", false, "--compile-for-tiered") {
|
}, new Option(" --compile-for-tiered Generate profiling code for tiered compilation", false, "--compile-for-tiered") {
|
||||||
@Override
|
@Override
|
||||||
void process(Main task, String opt, String arg) {
|
void process(Main task, String opt, String arg) {
|
||||||
TieredAOT.setValue(true);
|
TieredAOT.setValue(true);
|
||||||
}
|
}
|
||||||
|
}, new Option(" --compile-with-assertions Compile assertions", false, "--compile-with-assertions") {
|
||||||
|
@Override
|
||||||
|
void process(Main task, String opt, String arg) {
|
||||||
|
task.options.compileWithAssertions = true;
|
||||||
|
}
|
||||||
}, new Option(" --classpath <path> Specify where to find user class files", true, "--classpath", "--class-path") {
|
}, new Option(" --classpath <path> Specify where to find user class files", true, "--classpath", "--class-path") {
|
||||||
@Override
|
@Override
|
||||||
void process(Main task, String opt, String arg) {
|
void process(Main task, String opt, String arg) {
|
||||||
|
@ -225,15 +237,16 @@ public class Main implements LogPrinter {
|
||||||
*/
|
*/
|
||||||
private static final int COMPILER_THREADS = 16;
|
private static final int COMPILER_THREADS = 16;
|
||||||
|
|
||||||
int threads = Integer.min(COMPILER_THREADS, Runtime.getRuntime().availableProcessors());
|
public int threads = Integer.min(COMPILER_THREADS, Runtime.getRuntime().availableProcessors());
|
||||||
|
|
||||||
public boolean ignoreClassLoadingErrors;
|
public boolean ignoreClassLoadingErrors;
|
||||||
public boolean exitOnError;
|
public boolean exitOnError;
|
||||||
boolean info;
|
public boolean info;
|
||||||
boolean verbose;
|
public boolean verbose;
|
||||||
boolean debug;
|
public boolean debug;
|
||||||
boolean help;
|
public boolean help;
|
||||||
boolean version;
|
public boolean version;
|
||||||
|
public boolean compileWithAssertions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package */final Options options = new Options();
|
/* package */final Options options = new Options();
|
||||||
|
@ -356,6 +369,11 @@ public class Main implements LogPrinter {
|
||||||
AOTCompiler compiler = new AOTCompiler(this, aotBackend, options.threads);
|
AOTCompiler compiler = new AOTCompiler(this, aotBackend, options.threads);
|
||||||
classes = compiler.compileClasses(classes);
|
classes = compiler.compileClasses(classes);
|
||||||
|
|
||||||
|
GraalHotSpotVMConfig graalHotSpotVMConfig = runtime.getVMConfig();
|
||||||
|
PhaseSuite<HighTierContext> graphBuilderSuite = aotBackend.getGraphBuilderSuite();
|
||||||
|
ListIterator<BasePhase<? super HighTierContext>> iterator = graphBuilderSuite.findPhase(GraphBuilderPhase.class);
|
||||||
|
GraphBuilderConfiguration graphBuilderConfig = ((GraphBuilderPhase) iterator.previous()).getGraphBuilderConfig();
|
||||||
|
|
||||||
// Free memory!
|
// Free memory!
|
||||||
try (Timer t = options.verbose ? new Timer(this, "Freeing memory") : null) {
|
try (Timer t = options.verbose ? new Timer(this, "Freeing memory") : null) {
|
||||||
printMemoryUsage();
|
printMemoryUsage();
|
||||||
|
@ -364,7 +382,7 @@ public class Main implements LogPrinter {
|
||||||
System.gc();
|
System.gc();
|
||||||
}
|
}
|
||||||
|
|
||||||
BinaryContainer binaryContainer = new BinaryContainer(runtime.getVMConfig(), JVM_VERSION);
|
BinaryContainer binaryContainer = new BinaryContainer(graalHotSpotVMConfig, graphBuilderConfig, JVM_VERSION);
|
||||||
DataBuilder dataBuilder = new DataBuilder(this, backend, classes, binaryContainer);
|
DataBuilder dataBuilder = new DataBuilder(this, backend, classes, binaryContainer);
|
||||||
dataBuilder.prepareData();
|
dataBuilder.prepareData();
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
*/
|
*/
|
||||||
package org.graalvm.compiler.hotspot.meta;
|
package org.graalvm.compiler.hotspot.meta;
|
||||||
|
|
||||||
import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC;
|
|
||||||
import static org.graalvm.compiler.core.common.GraalOptions.ImmutableCode;
|
import static org.graalvm.compiler.core.common.GraalOptions.ImmutableCode;
|
||||||
import static org.graalvm.compiler.hotspot.meta.HotSpotGraalConstantFieldProvider.FieldReadEnabledInImmutableCode;
|
import static org.graalvm.compiler.hotspot.meta.HotSpotGraalConstantFieldProvider.FieldReadEnabledInImmutableCode;
|
||||||
|
|
||||||
|
@ -112,11 +111,6 @@ public final class HotSpotNodePlugin implements NodePlugin, TypePlugin {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (GeneratePIC.getValue()) {
|
|
||||||
if (field.isSynthetic() && field.getName().startsWith("$assertionsDisabled")) {
|
|
||||||
return tryReadField(b, field, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (b.parsingIntrinsic() && wordOperationPlugin.handleLoadStaticField(b, field)) {
|
if (b.parsingIntrinsic() && wordOperationPlugin.handleLoadStaticField(b, field)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include "aot/aotCodeHeap.hpp"
|
#include "aot/aotCodeHeap.hpp"
|
||||||
#include "aot/aotLoader.hpp"
|
#include "aot/aotLoader.hpp"
|
||||||
|
#include "classfile/javaAssertions.hpp"
|
||||||
#include "gc/g1/heapRegion.hpp"
|
#include "gc/g1/heapRegion.hpp"
|
||||||
#include "gc/shared/gcLocker.hpp"
|
#include "gc/shared/gcLocker.hpp"
|
||||||
#include "interpreter/abstractInterpreter.hpp"
|
#include "interpreter/abstractInterpreter.hpp"
|
||||||
|
@ -706,6 +707,12 @@ bool AOTCodeHeap::load_klass_data(instanceKlassHandle kh, Thread* thread) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_lib->config()->_omitAssertions && JavaAssertions::enabled(kh->name()->as_C_string(), kh->class_loader() == NULL)) {
|
||||||
|
// Assertions are omitted in the compiled code, but are enabled right now. Bail out.
|
||||||
|
sweep_dependent_methods(klass_data);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
NOT_PRODUCT( aot_klasses_found++; )
|
NOT_PRODUCT( aot_klasses_found++; )
|
||||||
|
|
||||||
log_trace(aot, class, load)("found %s in %s for classloader %p tid=" INTPTR_FORMAT, kh->internal_name(), _lib->name(), kh->class_loader_data(), p2i(thread));
|
log_trace(aot, class, load)("found %s in %s for classloader %p tid=" INTPTR_FORMAT, kh->internal_name(), _lib->name(), kh->class_loader_data(), p2i(thread));
|
||||||
|
@ -714,7 +721,7 @@ bool AOTCodeHeap::load_klass_data(instanceKlassHandle kh, Thread* thread) {
|
||||||
// Set klass's Resolve (second) got cell.
|
// Set klass's Resolve (second) got cell.
|
||||||
_metaspace_got[klass_data->_got_index] = kh();
|
_metaspace_got[klass_data->_got_index] = kh();
|
||||||
|
|
||||||
// Initialize global symbols of the DSO to the correspondingVM symbol values.
|
// Initialize global symbols of the DSO to the corresponding VM symbol values.
|
||||||
link_global_lib_symbols();
|
link_global_lib_symbols();
|
||||||
|
|
||||||
int methods_offset = klass_data->_compiled_methods_offset;
|
int methods_offset = klass_data->_compiled_methods_offset;
|
||||||
|
|
|
@ -88,7 +88,7 @@ typedef struct {
|
||||||
} AOTHeader;
|
} AOTHeader;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
enum { CONFIG_SIZE = 11 + 7 * 4 };
|
enum { CONFIG_SIZE = 12 + 7 * 4 };
|
||||||
int _config_size;
|
int _config_size;
|
||||||
int _narrowOopShift;
|
int _narrowOopShift;
|
||||||
int _narrowKlassShift;
|
int _narrowKlassShift;
|
||||||
|
@ -108,6 +108,7 @@ typedef struct {
|
||||||
bool _tieredAOT;
|
bool _tieredAOT;
|
||||||
bool _enableContended;
|
bool _enableContended;
|
||||||
bool _restrictContended;
|
bool _restrictContended;
|
||||||
|
bool _omitAssertions;
|
||||||
} AOTConfiguration;
|
} AOTConfiguration;
|
||||||
|
|
||||||
class AOTLib : public CHeapObj<mtCode> {
|
class AOTLib : public CHeapObj<mtCode> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue