Skip to content

Commit

Permalink
[GR-50240] Wrap HotSpotObjectConstant directly in ImageHeapConstant.
Browse files Browse the repository at this point in the history
PullRequest: graal/16870
  • Loading branch information
cstancu committed Feb 15, 2024
2 parents d5f9e5e + 6c47c24 commit 450475d
Show file tree
Hide file tree
Showing 43 changed files with 520 additions and 348 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static jdk.vm.ci.services.Services.IS_BUILDING_NATIVE_IMAGE;
import static jdk.vm.ci.services.Services.IS_IN_NATIVE_IMAGE;

import jdk.graal.compiler.api.replacements.SnippetReflectionProvider;
import jdk.graal.compiler.bytecode.BytecodeProvider;
import jdk.graal.compiler.core.common.spi.ConstantFieldProvider;
import jdk.graal.compiler.debug.Assertions;
Expand Down Expand Up @@ -56,6 +57,7 @@
import jdk.graal.compiler.nodes.java.AbstractNewObjectNode;
import jdk.graal.compiler.nodes.loop.LoopsDataProviderImpl;
import jdk.graal.compiler.nodes.memory.FixedAccessNode;
import jdk.graal.compiler.nodes.spi.IdentityHashCodeProvider;
import jdk.graal.compiler.nodes.spi.LoopsDataProvider;
import jdk.graal.compiler.nodes.spi.Replacements;
import jdk.graal.compiler.options.OptionValues;
Expand Down Expand Up @@ -188,9 +190,12 @@ public final HotSpotBackend createBackend(HotSpotGraalRuntimeProvider graalRunti
try (InitTimer rt = timer("create Bytecode provider")) {
bytecodeProvider = createBytecodeProvider(metaAccess, snippetReflection);
}

IdentityHashCodeProvider identityHashCodeProvider;
try (InitTimer rt = timer("create IdentityHashCode provider")) {
identityHashCodeProvider = createIdentityHashCodeProvider(snippetReflection);
}
providers = new HotSpotProviders(metaAccess, codeCache, constantReflection, constantFieldProvider, foreignCalls, lowerer, null, null, registers,
snippetReflection, wordTypes, stampProvider, platformConfigurationProvider, metaAccessExtensionProvider, loopsDataProvider, config);
snippetReflection, wordTypes, stampProvider, platformConfigurationProvider, metaAccessExtensionProvider, loopsDataProvider, config, identityHashCodeProvider);
HotSpotReplacementsImpl replacements;
try (InitTimer rt = timer("create Replacements provider")) {
replacements = createReplacements(target, providers, bytecodeProvider);
Expand All @@ -217,6 +222,10 @@ public final HotSpotBackend createBackend(HotSpotGraalRuntimeProvider graalRunti
}
}

protected IdentityHashCodeProvider createIdentityHashCodeProvider(SnippetReflectionProvider snippetReflection) {
return new IdentityHashCodeProvider(snippetReflection);
}

protected abstract HotSpotBackend createBackend(GraalHotSpotVMConfig config, HotSpotGraalRuntimeProvider graalRuntime, HotSpotProviders providers);

protected abstract Value[] createNativeABICallerSaveRegisters(GraalHotSpotVMConfig config, RegisterConfig registerConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ private boolean verifySnippetEncodeDecode(DebugContext debug, ResolvedJavaMethod
HotSpotProviders newProviders = new HotSpotProviders(originalProvider.getMetaAccess(), originalProvider.getCodeCache(), constantReflection,
originalProvider.getConstantFieldProvider(), originalProvider.getForeignCalls(), originalProvider.getLowerer(), null, originalProvider.getSuites(),
originalProvider.getRegisters(), originalProvider.getSnippetReflection(), originalProvider.getWordTypes(), originalProvider.getStampProvider(),
originalProvider.getPlatformConfigurationProvider(), originalProvider.getMetaAccessExtensionProvider(), originalProvider.getLoopsDataProvider(), originalProvider.getConfig());
originalProvider.getPlatformConfigurationProvider(), originalProvider.getMetaAccessExtensionProvider(), originalProvider.getLoopsDataProvider(), originalProvider.getConfig(),
originalProvider.getIdentityHashCodeProvider());
HotSpotSnippetReplacementsImpl filteringReplacements = new HotSpotSnippetReplacementsImpl(newProviders,
originalProvider.getReplacements().getDefaultReplacementBytecodeProvider(), originalProvider.getCodeCache().getTarget());
filteringReplacements.setGraphBuilderPlugins(originalProvider.getReplacements().getGraphBuilderPlugins());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
import jdk.graal.compiler.hotspot.GraalHotSpotVMConfig;
import jdk.graal.compiler.hotspot.word.HotSpotWordTypes;
import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
import jdk.graal.compiler.nodes.spi.IdentityHashCodeProvider;
import jdk.graal.compiler.nodes.spi.LoopsDataProvider;
import jdk.graal.compiler.nodes.spi.LoweringProvider;
import jdk.graal.compiler.nodes.spi.PlatformConfigurationProvider;
import jdk.graal.compiler.nodes.spi.Replacements;
import jdk.graal.compiler.nodes.spi.StampProvider;
import jdk.graal.compiler.phases.tiers.SuitesProvider;
import jdk.graal.compiler.phases.util.Providers;

import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider;
import jdk.vm.ci.meta.ConstantReflectionProvider;
import jdk.vm.ci.meta.MetaAccessProvider;
Expand Down Expand Up @@ -67,9 +67,10 @@ public HotSpotProviders(MetaAccessProvider metaAccess,
PlatformConfigurationProvider platformConfigurationProvider,
MetaAccessExtensionProvider metaAccessExtensionProvider,
LoopsDataProvider loopsDataProvider,
GraalHotSpotVMConfig config) {
GraalHotSpotVMConfig config,
IdentityHashCodeProvider identityHashCodeProvider) {
super(metaAccess, codeCache, constantReflection, constantField, foreignCalls, lowerer, replacements, stampProvider, platformConfigurationProvider, metaAccessExtensionProvider,
snippetReflection, wordTypes, loopsDataProvider);
snippetReflection, wordTypes, loopsDataProvider, identityHashCodeProvider);
this.suites = suites;
this.registers = registers;
this.config = config;
Expand Down Expand Up @@ -116,7 +117,7 @@ public HotSpotProviders copyWith(ConstantReflectionProvider substitution) {
return new HotSpotProviders(getMetaAccess(), getCodeCache(), substitution, getConstantFieldProvider(), getForeignCalls(), getLowerer(), getReplacements(), getSuites(),
getRegisters(), getSnippetReflection(), getWordTypes(), getStampProvider(), getPlatformConfigurationProvider(), getMetaAccessExtensionProvider(),
getLoopsDataProvider(),
config);
config, getIdentityHashCodeProvider());
}

@Override
Expand All @@ -125,22 +126,22 @@ public HotSpotProviders copyWith(ConstantFieldProvider substitution) {
getSuites(),
getRegisters(), getSnippetReflection(), getWordTypes(), getStampProvider(), getPlatformConfigurationProvider(), getMetaAccessExtensionProvider(),
getLoopsDataProvider(),
config);
config, getIdentityHashCodeProvider());
}

@Override
public HotSpotProviders copyWith(Replacements substitution) {
return new HotSpotProviders(getMetaAccess(), getCodeCache(), getConstantReflection(), getConstantFieldProvider(), getForeignCalls(), getLowerer(), substitution,
getSuites(), getRegisters(), getSnippetReflection(), getWordTypes(), getStampProvider(), getPlatformConfigurationProvider(),
getMetaAccessExtensionProvider(),
getLoopsDataProvider(), config);
getLoopsDataProvider(), config, getIdentityHashCodeProvider());
}

public HotSpotProviders copyWith() {
return new HotSpotProviders(getMetaAccess(), getCodeCache(), getConstantReflection(), getConstantFieldProvider(), getForeignCalls(), getLowerer(), getReplacements(),
getSuites(), getRegisters(), getSnippetReflection(), getWordTypes(), getStampProvider(), getPlatformConfigurationProvider(), getMetaAccessExtensionProvider(),
getLoopsDataProvider(),
config);
config, getIdentityHashCodeProvider());
}

public void setSuites(HotSpotSuitesProvider suites) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,6 @@ public interface CoreProviders {
CodeCacheProvider getCodeCache();

SnippetReflectionProvider getSnippetReflection();

IdentityHashCodeProvider getIdentityHashCodeProvider();
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,9 @@ public WordTypes getWordTypes() {
public SnippetReflectionProvider getSnippetReflection() {
return providers.getSnippetReflection();
}

@Override
public IdentityHashCodeProvider getIdentityHashCodeProvider() {
return providers.getIdentityHashCodeProvider();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.graal.compiler.nodes.spi;

import jdk.graal.compiler.api.replacements.SnippetReflectionProvider;
import jdk.vm.ci.meta.JavaConstant;

public class IdentityHashCodeProvider {

protected final SnippetReflectionProvider snippetReflection;

public IdentityHashCodeProvider(SnippetReflectionProvider snippetReflection) {
this.snippetReflection = snippetReflection;
}

public int identityHashCode(JavaConstant constant) {
return System.identityHashCode(snippetReflection.asObject(Object.class, constant));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public RawConditionalEliminationVisitor(StructuredGraph graph, ScheduleResult sc
this.debug = graph.getDebug();
this.schedule = schedule;
this.metaAccess = metaAccess;
this.rawCanonicalizerTool = new RawCanonicalizerTool(new Providers(metaAccess, null, null, null, null, null, null, null, null, null, null, null, null));
this.rawCanonicalizerTool = new RawCanonicalizerTool(new Providers(metaAccess, null, null, null, null, null, null, null, null, null, null, null, null, null));
blockActionStart = new BlockMap<>(schedule.getCFG());
endMaps = EconomicMap.create(Equivalence.IDENTITY);
stampMap = graph.createNodeMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import jdk.graal.compiler.core.common.spi.ForeignCallsProvider;
import jdk.graal.compiler.core.common.spi.MetaAccessExtensionProvider;
import jdk.graal.compiler.nodes.spi.CoreProviders;
import jdk.graal.compiler.nodes.spi.IdentityHashCodeProvider;
import jdk.graal.compiler.nodes.spi.LoopsDataProvider;
import jdk.graal.compiler.nodes.spi.LoweringProvider;
import jdk.graal.compiler.nodes.spi.PlatformConfigurationProvider;
Expand Down Expand Up @@ -57,10 +58,12 @@ public class Providers implements CoreProviders {
protected final CodeCacheProvider codeCache;
protected final SnippetReflectionProvider snippetReflection;
protected final WordTypes wordTypes;
protected final IdentityHashCodeProvider identityHashCodeProvider;

public Providers(MetaAccessProvider metaAccess, CodeCacheProvider codeCache, ConstantReflectionProvider constantReflection, ConstantFieldProvider constantFieldProvider,
ForeignCallsProvider foreignCalls, LoweringProvider lowerer, Replacements replacements, StampProvider stampProvider, PlatformConfigurationProvider platformConfigurationProvider,
MetaAccessExtensionProvider metaAccessExtensionProvider, SnippetReflectionProvider snippetReflection, WordTypes wordTypes, LoopsDataProvider loopsDataProvider) {
MetaAccessExtensionProvider metaAccessExtensionProvider, SnippetReflectionProvider snippetReflection, WordTypes wordTypes, LoopsDataProvider loopsDataProvider,
IdentityHashCodeProvider identityHashCodeProvider) {
this.metaAccess = metaAccess;
this.constantReflection = constantReflection;
this.constantFieldProvider = constantFieldProvider;
Expand All @@ -74,12 +77,13 @@ public Providers(MetaAccessProvider metaAccess, CodeCacheProvider codeCache, Con
this.codeCache = codeCache;
this.snippetReflection = snippetReflection;
this.wordTypes = wordTypes;
this.identityHashCodeProvider = identityHashCodeProvider;
}

public Providers(Providers copyFrom) {
this(copyFrom.getMetaAccess(), copyFrom.getCodeCache(), copyFrom.getConstantReflection(), copyFrom.getConstantFieldProvider(), copyFrom.getForeignCalls(), copyFrom.getLowerer(),
copyFrom.getReplacements(), copyFrom.getStampProvider(), copyFrom.getPlatformConfigurationProvider(), copyFrom.getMetaAccessExtensionProvider(),
copyFrom.getSnippetReflection(), copyFrom.getWordTypes(), copyFrom.getLoopsDataProvider());
copyFrom.getSnippetReflection(), copyFrom.getWordTypes(), copyFrom.getLoopsDataProvider(), copyFrom.getIdentityHashCodeProvider());
}

@Override
Expand Down Expand Up @@ -142,6 +146,11 @@ public SnippetReflectionProvider getSnippetReflection() {
return snippetReflection;
}

@Override
public IdentityHashCodeProvider getIdentityHashCodeProvider() {
return identityHashCodeProvider;
}

@Override
public WordTypes getWordTypes() {
return wordTypes;
Expand All @@ -150,24 +159,24 @@ public WordTypes getWordTypes() {
public Providers copyWith(ConstantReflectionProvider substitution) {
assert this.getClass() == Providers.class : "must override";
return new Providers(metaAccess, codeCache, substitution, constantFieldProvider, foreignCalls, lowerer, replacements, stampProvider, platformConfigurationProvider, metaAccessExtensionProvider,
snippetReflection, wordTypes, loopsDataProvider);
snippetReflection, wordTypes, loopsDataProvider, identityHashCodeProvider);
}

public Providers copyWith(ConstantFieldProvider substitution) {
assert this.getClass() == Providers.class : "must override";
return new Providers(metaAccess, codeCache, constantReflection, substitution, foreignCalls, lowerer, replacements, stampProvider, platformConfigurationProvider, metaAccessExtensionProvider,
snippetReflection, wordTypes, loopsDataProvider);
snippetReflection, wordTypes, loopsDataProvider, identityHashCodeProvider);
}

public Providers copyWith(Replacements substitution) {
assert this.getClass() == Providers.class : "must override in " + getClass();
return new Providers(metaAccess, codeCache, constantReflection, constantFieldProvider, foreignCalls, lowerer, substitution, stampProvider, platformConfigurationProvider,
metaAccessExtensionProvider, snippetReflection, wordTypes, loopsDataProvider);
metaAccessExtensionProvider, snippetReflection, wordTypes, loopsDataProvider, identityHashCodeProvider);
}

public Providers copyWith(MetaAccessExtensionProvider substitution) {
assert this.getClass() == Providers.class : getClass() + " must override";
return new Providers(metaAccess, codeCache, constantReflection, constantFieldProvider, foreignCalls, lowerer, replacements, stampProvider, platformConfigurationProvider, substitution,
snippetReflection, wordTypes, loopsDataProvider);
snippetReflection, wordTypes, loopsDataProvider, identityHashCodeProvider);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import jdk.graal.compiler.debug.Indent;
import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins;
import jdk.graal.compiler.nodes.spi.IdentityHashCodeProvider;
import jdk.graal.compiler.options.OptionValues;
import jdk.graal.compiler.phases.util.Providers;
import jdk.graal.compiler.printer.GraalDebugHandlersFactory;
Expand Down Expand Up @@ -147,10 +148,11 @@ private PointsToAnalyzer(String mainEntryClass, OptionValues options) {
StandaloneConstantReflectionProvider aConstantReflection = new StandaloneConstantReflectionProvider(aUniverse, HotSpotJVMCIRuntime.runtime());
StandaloneConstantFieldProvider aConstantFieldProvider = new StandaloneConstantFieldProvider(aMetaAccess);
AnalysisMetaAccessExtensionProvider aMetaAccessExtensionProvider = new AnalysisMetaAccessExtensionProvider();
IdentityHashCodeProvider identityHashCodeProvider = originalProviders.getIdentityHashCodeProvider();
HostedProviders aProviders = new HostedProviders(aMetaAccess, null, aConstantReflection, aConstantFieldProvider,
originalProviders.getForeignCalls(), originalProviders.getLowerer(), originalProviders.getReplacements(),
originalProviders.getStampProvider(), snippetReflection, new WordTypes(aMetaAccess, wordKind),
originalProviders.getPlatformConfigurationProvider(), aMetaAccessExtensionProvider, originalProviders.getLoopsDataProvider());
originalProviders.getPlatformConfigurationProvider(), aMetaAccessExtensionProvider, originalProviders.getLoopsDataProvider(), identityHashCodeProvider);
standaloneHost.initializeProviders(aProviders);
analysisName = getAnalysisName(mainEntryClass);
ClassInclusionPolicy classInclusionPolicy = new ClassInclusionPolicy.DefaultAllInclusionPolicy("Included in the base image");
Expand All @@ -160,7 +162,7 @@ private PointsToAnalyzer(String mainEntryClass, OptionValues options) {
aUniverse.setBigBang(bigbang);
ImageHeap heap = new ImageHeap();
StandaloneImageHeapScanner heapScanner = new StandaloneImageHeapScanner(bigbang, heap, aMetaAccess,
snippetReflection, aConstantReflection, new AnalysisObjectScanningObserver(bigbang), analysisClassLoader, new HostedValuesProvider(aUniverse));
snippetReflection, aConstantReflection, new AnalysisObjectScanningObserver(bigbang), analysisClassLoader, new HostedValuesProvider(aUniverse), identityHashCodeProvider);
aUniverse.setHeapScanner(heapScanner);
HeapSnapshotVerifier heapVerifier = new StandaloneHeapSnapshotVerifier(bigbang, heap, heapScanner);
aUniverse.setHeapVerifier(heapVerifier);
Expand Down
Loading

0 comments on commit 450475d

Please sign in to comment.