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.elf.JELFRelocObject;
|
||||
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.
|
||||
|
@ -257,9 +258,9 @@ public class BinaryContainer implements SymbolTable {
|
|||
* prefix {@code prefix}. It also initializes internal code container, symbol table and
|
||||
* relocation tables.
|
||||
*/
|
||||
public BinaryContainer(GraalHotSpotVMConfig config, String jvmVersion) {
|
||||
this.codeSegmentSize = config.codeSegmentSize;
|
||||
this.codeEntryAlignment = config.codeEntryAlignment;
|
||||
public BinaryContainer(GraalHotSpotVMConfig graalHotSpotVMConfig, GraphBuilderConfiguration graphBuilderConfig, String jvmVersion) {
|
||||
this.codeSegmentSize = graalHotSpotVMConfig.codeSegmentSize;
|
||||
this.codeEntryAlignment = graalHotSpotVMConfig.codeEntryAlignment;
|
||||
|
||||
// read only, code
|
||||
codeContainer = new CodeContainer(".text", this);
|
||||
|
@ -289,30 +290,31 @@ public class BinaryContainer implements SymbolTable {
|
|||
|
||||
addGlobalSymbols();
|
||||
|
||||
recordConfiguration(config);
|
||||
recordConfiguration(graalHotSpotVMConfig, graphBuilderConfig);
|
||||
}
|
||||
|
||||
private void recordConfiguration(GraalHotSpotVMConfig config) {
|
||||
private void recordConfiguration(GraalHotSpotVMConfig graalHotSpotVMConfig, GraphBuilderConfiguration graphBuilderConfig) {
|
||||
// @formatter:off
|
||||
boolean[] booleanFlags = { config.cAssertions, // Debug VM
|
||||
config.useCompressedOops,
|
||||
config.useCompressedClassPointers,
|
||||
config.compactFields,
|
||||
config.useG1GC,
|
||||
config.useCMSGC,
|
||||
config.useTLAB,
|
||||
config.useBiasedLocking,
|
||||
boolean[] booleanFlags = { graalHotSpotVMConfig.cAssertions, // Debug VM
|
||||
graalHotSpotVMConfig.useCompressedOops,
|
||||
graalHotSpotVMConfig.useCompressedClassPointers,
|
||||
graalHotSpotVMConfig.compactFields,
|
||||
graalHotSpotVMConfig.useG1GC,
|
||||
graalHotSpotVMConfig.useCMSGC,
|
||||
graalHotSpotVMConfig.useTLAB,
|
||||
graalHotSpotVMConfig.useBiasedLocking,
|
||||
TieredAOT.getValue(),
|
||||
config.enableContended,
|
||||
config.restrictContended,
|
||||
graalHotSpotVMConfig.enableContended,
|
||||
graalHotSpotVMConfig.restrictContended,
|
||||
graphBuilderConfig.omitAssertions()
|
||||
};
|
||||
|
||||
int[] intFlags = { config.narrowOopShift,
|
||||
config.narrowKlassShift,
|
||||
config.contendedPaddingWidth,
|
||||
config.fieldsAllocationStyle,
|
||||
config.objectAlignment,
|
||||
config.codeSegmentSize,
|
||||
int[] intFlags = { graalHotSpotVMConfig.narrowOopShift,
|
||||
graalHotSpotVMConfig.narrowKlassShift,
|
||||
graalHotSpotVMConfig.contendedPaddingWidth,
|
||||
graalHotSpotVMConfig.fieldsAllocationStyle,
|
||||
graalHotSpotVMConfig.objectAlignment,
|
||||
graalHotSpotVMConfig.codeSegmentSize,
|
||||
};
|
||||
// @formatter:on
|
||||
|
||||
|
|
|
@ -77,10 +77,14 @@ public class AOTBackend {
|
|||
this.filters = filters;
|
||||
providers = backend.getProviders();
|
||||
codeCache = providers.getCodeCache();
|
||||
graphBuilderSuite = initGraphBuilderSuite(backend);
|
||||
graphBuilderSuite = initGraphBuilderSuite(backend, main.options.compileWithAssertions);
|
||||
highTierContext = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.ALL);
|
||||
}
|
||||
|
||||
public PhaseSuite<HighTierContext> getGraphBuilderSuite() {
|
||||
return graphBuilderSuite;
|
||||
}
|
||||
|
||||
private Suites getSuites() {
|
||||
// create suites every time, as we modify options for the compiler
|
||||
return backend.getSuites().getDefaultSuites();
|
||||
|
@ -146,14 +150,14 @@ public class AOTBackend {
|
|||
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();
|
||||
ListIterator<BasePhase<? super HighTierContext>> iterator = graphBuilderSuite.findPhase(GraphBuilderPhase.class);
|
||||
GraphBuilderConfiguration baseConfig = ((GraphBuilderPhase) iterator.previous()).getGraphBuilderConfig();
|
||||
|
||||
// Use all default plugins.
|
||||
Plugins plugins = baseConfig.getPlugins();
|
||||
GraphBuilderConfiguration aotConfig = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true);
|
||||
GraphBuilderConfiguration aotConfig = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withOmitAssertions(!compileWithAssertions);
|
||||
|
||||
iterator.next();
|
||||
iterator.remove();
|
||||
|
|
|
@ -45,6 +45,7 @@ import java.util.ArrayList;
|
|||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
@ -54,8 +55,14 @@ import jdk.tools.jaotc.collect.ClassCollector;
|
|||
import jdk.tools.jaotc.utils.Timer;
|
||||
|
||||
import org.graalvm.compiler.api.runtime.GraalJVMCICompiler;
|
||||
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
|
||||
import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
|
||||
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 jdk.vm.ci.meta.MetaAccessProvider;
|
||||
|
@ -144,11 +151,16 @@ public class Main implements LogPrinter {
|
|||
void process(Main task, String opt, String 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
|
||||
void process(Main task, String opt, String arg) {
|
||||
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") {
|
||||
@Override
|
||||
void process(Main task, String opt, String arg) {
|
||||
|
@ -225,15 +237,16 @@ public class Main implements LogPrinter {
|
|||
*/
|
||||
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 exitOnError;
|
||||
boolean info;
|
||||
boolean verbose;
|
||||
boolean debug;
|
||||
boolean help;
|
||||
boolean version;
|
||||
public boolean info;
|
||||
public boolean verbose;
|
||||
public boolean debug;
|
||||
public boolean help;
|
||||
public boolean version;
|
||||
public boolean compileWithAssertions;
|
||||
}
|
||||
|
||||
/* package */final Options options = new Options();
|
||||
|
@ -356,6 +369,11 @@ public class Main implements LogPrinter {
|
|||
AOTCompiler compiler = new AOTCompiler(this, aotBackend, options.threads);
|
||||
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!
|
||||
try (Timer t = options.verbose ? new Timer(this, "Freeing memory") : null) {
|
||||
printMemoryUsage();
|
||||
|
@ -364,7 +382,7 @@ public class Main implements LogPrinter {
|
|||
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.prepareData();
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
*/
|
||||
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.hotspot.meta.HotSpotGraalConstantFieldProvider.FieldReadEnabledInImmutableCode;
|
||||
|
||||
|
@ -112,11 +111,6 @@ public final class HotSpotNodePlugin implements NodePlugin, TypePlugin {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
if (GeneratePIC.getValue()) {
|
||||
if (field.isSynthetic() && field.getName().startsWith("$assertionsDisabled")) {
|
||||
return tryReadField(b, field, null);
|
||||
}
|
||||
}
|
||||
if (b.parsingIntrinsic() && wordOperationPlugin.handleLoadStaticField(b, field)) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include "aot/aotCodeHeap.hpp"
|
||||
#include "aot/aotLoader.hpp"
|
||||
#include "classfile/javaAssertions.hpp"
|
||||
#include "gc/g1/heapRegion.hpp"
|
||||
#include "gc/shared/gcLocker.hpp"
|
||||
#include "interpreter/abstractInterpreter.hpp"
|
||||
|
@ -706,6 +707,12 @@ bool AOTCodeHeap::load_klass_data(instanceKlassHandle kh, Thread* thread) {
|
|||
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++; )
|
||||
|
||||
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.
|
||||
_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();
|
||||
|
||||
int methods_offset = klass_data->_compiled_methods_offset;
|
||||
|
|
|
@ -88,7 +88,7 @@ typedef struct {
|
|||
} AOTHeader;
|
||||
|
||||
typedef struct {
|
||||
enum { CONFIG_SIZE = 11 + 7 * 4 };
|
||||
enum { CONFIG_SIZE = 12 + 7 * 4 };
|
||||
int _config_size;
|
||||
int _narrowOopShift;
|
||||
int _narrowKlassShift;
|
||||
|
@ -108,6 +108,7 @@ typedef struct {
|
|||
bool _tieredAOT;
|
||||
bool _enableContended;
|
||||
bool _restrictContended;
|
||||
bool _omitAssertions;
|
||||
} AOTConfiguration;
|
||||
|
||||
class AOTLib : public CHeapObj<mtCode> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue