-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GR-54709] Introduce ApplicationLayerOnly and MultiLayer Image Single…
…tons. PullRequest: graal/18024
- Loading branch information
Showing
28 changed files
with
1,264 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
...m/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/nodes/LoadImageSingletonNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright (c) 2024, 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 com.oracle.svm.core.graal.nodes; | ||
|
||
import com.oracle.svm.core.heap.ReferenceAccess; | ||
import com.oracle.svm.core.imagelayer.LoadImageSingletonFactory.LoadImageSingletonData; | ||
|
||
import jdk.graal.compiler.core.common.memory.BarrierType; | ||
import jdk.graal.compiler.core.common.memory.MemoryOrderMode; | ||
import jdk.graal.compiler.core.common.type.AbstractObjectStamp; | ||
import jdk.graal.compiler.core.common.type.Stamp; | ||
import jdk.graal.compiler.core.common.type.StampFactory; | ||
import jdk.graal.compiler.core.common.type.TypeReference; | ||
import jdk.graal.compiler.graph.Node; | ||
import jdk.graal.compiler.graph.NodeClass; | ||
import jdk.graal.compiler.nodeinfo.NodeCycles; | ||
import jdk.graal.compiler.nodeinfo.NodeInfo; | ||
import jdk.graal.compiler.nodeinfo.NodeSize; | ||
import jdk.graal.compiler.nodes.CompressionNode; | ||
import jdk.graal.compiler.nodes.ConstantNode; | ||
import jdk.graal.compiler.nodes.FixedWithNextNode; | ||
import jdk.graal.compiler.nodes.NamedLocationIdentity; | ||
import jdk.graal.compiler.nodes.NodeView; | ||
import jdk.graal.compiler.nodes.StructuredGraph; | ||
import jdk.graal.compiler.nodes.memory.ReadNode; | ||
import jdk.graal.compiler.nodes.memory.address.AddressNode; | ||
import jdk.graal.compiler.nodes.memory.address.OffsetAddressNode; | ||
import jdk.graal.compiler.nodes.spi.Canonicalizable; | ||
import jdk.graal.compiler.nodes.spi.CanonicalizerTool; | ||
import jdk.graal.compiler.nodes.spi.Lowerable; | ||
import jdk.graal.compiler.nodes.spi.LoweringTool; | ||
import jdk.vm.ci.meta.JavaKind; | ||
import jdk.vm.ci.meta.MetaAccessProvider; | ||
|
||
@NodeInfo(cycles = NodeCycles.CYCLES_4, size = NodeSize.SIZE_2) | ||
public class LoadImageSingletonNode extends FixedWithNextNode implements Lowerable, Canonicalizable { | ||
public static final NodeClass<LoadImageSingletonNode> TYPE = NodeClass.create(LoadImageSingletonNode.class); | ||
|
||
private final LoadImageSingletonData singletonInfo; | ||
|
||
protected LoadImageSingletonNode(LoadImageSingletonData singletonInfo, Stamp stamp) { | ||
super(TYPE, stamp); | ||
this.singletonInfo = singletonInfo; | ||
} | ||
|
||
public static LoadImageSingletonNode createLoadImageSingleton(LoadImageSingletonData singletonInfo, MetaAccessProvider metaAccess) { | ||
return new LoadImageSingletonNode(singletonInfo, StampFactory.objectNonNull(TypeReference.createExactTrusted(metaAccess.lookupJavaType(singletonInfo.getLoadType())))); | ||
} | ||
|
||
@Override | ||
public Node canonical(CanonicalizerTool tool) { | ||
if (tool.allUsagesAvailable() && hasNoUsages()) { | ||
// can remove this load if it is never used. | ||
return null; | ||
} | ||
|
||
return this; | ||
} | ||
|
||
@Override | ||
public void lower(LoweringTool tool) { | ||
StructuredGraph graph = graph(); | ||
var singletonAccessInfo = singletonInfo.getAccessInfo(); | ||
|
||
/* | ||
* Load the starting address of the singleton table. | ||
*/ | ||
|
||
CGlobalDataLoadAddressNode baseAddress = graph.unique(new CGlobalDataLoadAddressNode(singletonAccessInfo.tableBase())); | ||
|
||
/* | ||
* Read from the appropriate offset of the singleton table. | ||
*/ | ||
|
||
AddressNode address = graph.unique(new OffsetAddressNode(baseAddress, ConstantNode.forIntegerKind(JavaKind.Long, singletonAccessInfo.offset(), graph))); | ||
var tableReadStamp = SubstrateNarrowOopStamp.compressed((AbstractObjectStamp) stamp(NodeView.DEFAULT), ReferenceAccess.singleton().getCompressEncoding()); | ||
ReadNode tableRead = graph.add(new ReadNode(address, NamedLocationIdentity.FINAL_LOCATION, tableReadStamp, BarrierType.NONE, MemoryOrderMode.PLAIN)); | ||
|
||
CompressionNode uncompress = SubstrateCompressionNode.uncompress(graph(), tableRead, ReferenceAccess.singleton().getCompressEncoding()); | ||
|
||
replaceAtUsages(uncompress); | ||
graph.replaceFixed(this, tableRead); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...m/src/com.oracle.svm.core/src/com/oracle/svm/core/imagelayer/LastImageBuildPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (c) 2024, 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 com.oracle.svm.core.imagelayer; | ||
|
||
import java.util.function.BooleanSupplier; | ||
|
||
import org.graalvm.nativeimage.Platform; | ||
import org.graalvm.nativeimage.Platforms; | ||
|
||
@Platforms(Platform.HOSTED_ONLY.class) | ||
public class LastImageBuildPredicate implements BooleanSupplier { | ||
@Override | ||
public boolean getAsBoolean() { | ||
return ImageLayerBuildingSupport.lastImageBuild(); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...src/com.oracle.svm.core/src/com/oracle/svm/core/imagelayer/LoadImageSingletonFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) 2024, 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 com.oracle.svm.core.imagelayer; | ||
|
||
import org.graalvm.nativeimage.ImageSingletons; | ||
|
||
import com.oracle.svm.core.graal.code.CGlobalDataInfo; | ||
import com.oracle.svm.core.graal.nodes.LoadImageSingletonNode; | ||
|
||
import jdk.vm.ci.meta.MetaAccessProvider; | ||
|
||
public abstract class LoadImageSingletonFactory { | ||
|
||
public record SingletonAccessInfo(CGlobalDataInfo tableBase, int offset) { | ||
|
||
} | ||
|
||
/** | ||
* Provides compiler-relevant information about the value which will be loaded. | ||
*/ | ||
public interface LoadImageSingletonData { | ||
|
||
Class<?> getLoadType(); | ||
|
||
SingletonAccessInfo getAccessInfo(); | ||
} | ||
|
||
protected abstract LoadImageSingletonData getApplicationLayerOnlyImageSingletonInfo(Class<?> clazz); | ||
|
||
protected abstract LoadImageSingletonData getLayeredImageSingletonInfo(Class<?> clazz); | ||
|
||
public static LoadImageSingletonNode loadApplicationOnlyImageSingleton(Class<?> clazz, MetaAccessProvider metaAccess) { | ||
LoadImageSingletonData singletonInfo = ImageSingletons.lookup(LoadImageSingletonFactory.class).getApplicationLayerOnlyImageSingletonInfo(clazz); | ||
return LoadImageSingletonNode.createLoadImageSingleton(singletonInfo, metaAccess); | ||
} | ||
|
||
public static LoadImageSingletonNode loadLayeredImageSingleton(Class<?> clazz, MetaAccessProvider metaAccess) { | ||
LoadImageSingletonData singletonInfo = ImageSingletons.lookup(LoadImageSingletonFactory.class).getLayeredImageSingletonInfo(clazz); | ||
return LoadImageSingletonNode.createLoadImageSingleton(singletonInfo, metaAccess); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...ore/src/com/oracle/svm/core/layeredimagesingleton/ApplicationLayerOnlyImageSingleton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (c) 2024, 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 com.oracle.svm.core.layeredimagesingleton; | ||
|
||
public interface ApplicationLayerOnlyImageSingleton extends LayeredImageSingleton { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.