Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2018, 2023, 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.hotspot;
import static jdk.graal.compiler.hotspot.HotSpotReplacementsImpl.isGraalClass;
import static jdk.graal.compiler.nodes.graphbuilderconf.IntrinsicContext.CompilationContext.INLINE_AFTER_PARSING;
import static org.graalvm.nativeimage.ImageInfo.inImageRuntimeCode;
import java.lang.reflect.Executable;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import org.graalvm.collections.UnmodifiableEconomicMap;
import jdk.graal.compiler.api.replacements.SnippetReflectionProvider;
import jdk.graal.compiler.bytecode.BytecodeProvider;
import jdk.graal.compiler.bytecode.ResolvedJavaMethodBytecode;
import jdk.graal.compiler.core.common.type.Stamp;
import jdk.graal.compiler.core.common.type.StampPair;
import jdk.graal.compiler.core.common.type.SymbolicJVMCIReference;
import jdk.graal.compiler.debug.DebugContext;
import jdk.graal.compiler.debug.GraalError;
import jdk.graal.compiler.graph.NodeClass;
import jdk.graal.compiler.nodeinfo.Verbosity;
import jdk.graal.compiler.nodes.ConstantNode;
import jdk.graal.compiler.nodes.EncodedGraph;
import jdk.graal.compiler.nodes.FieldLocationIdentity;
import jdk.graal.compiler.nodes.StructuredGraph;
import jdk.graal.compiler.nodes.ValueNode;
import jdk.graal.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
import jdk.graal.compiler.nodes.graphbuilderconf.IntrinsicContext;
import jdk.graal.compiler.nodes.graphbuilderconf.ParameterPlugin;
import jdk.graal.compiler.nodes.java.MethodCallTargetNode;
import jdk.graal.compiler.nodes.spi.SnippetParameterInfo;
import jdk.graal.compiler.options.OptionValues;
import jdk.graal.compiler.phases.util.Providers;
import jdk.graal.compiler.replacements.ConstantBindingParameterPlugin;
import jdk.graal.compiler.replacements.PEGraphDecoder;
import jdk.graal.compiler.replacements.PartialIntrinsicCallTargetNode;
import jdk.vm.ci.meta.JavaConstant;
import jdk.vm.ci.meta.JavaKind;
import jdk.vm.ci.meta.MetaAccessProvider;
import jdk.vm.ci.meta.ResolvedJavaField;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.ResolvedJavaType;
import jdk.vm.ci.meta.UnresolvedJavaField;
import jdk.vm.ci.meta.UnresolvedJavaMethod;
import jdk.vm.ci.meta.UnresolvedJavaType;
public class EncodedSnippets {
abstract static class GraphData {
int startOffset;
String originalMethod;
SnippetParameterInfo info;
GraphData(int startOffset, String originalMethod, SnippetParameterInfo info) {
this.startOffset = startOffset;
this.originalMethod = originalMethod;
this.info = info;
}
/**
* Record the data for an encoded graph. Most graphs are from static methods and can only
* have a single instantiation but snippets might come for a non-static method and rely on
* the type of the receiver to devirtualize invokes. In that case each pair of method and
* receiver represents a potentially different instantiation and these are linked into a
* chain of {@link VirtualGraphData VirtualGraphDatas}.
*
* @param startOffset offset of the encoded graph
* @param originalMethod method parsed for the graph
* @param snippetParameterInfo parameter information for snippets
* @param receiverClass static type of the receiver for non-virtual methods
* @param existingGraph a previous encoding of this same graph
*/
public static GraphData create(int startOffset, String originalMethod, SnippetParameterInfo snippetParameterInfo, Class> receiverClass, GraphData existingGraph) {
if (receiverClass == null) {
assert existingGraph == null : originalMethod;
return new StaticGraphData(startOffset, originalMethod, snippetParameterInfo);
} else {
return new VirtualGraphData(startOffset, originalMethod, snippetParameterInfo, receiverClass, (VirtualGraphData) existingGraph);
}
}
/**
* Return the proper starting offset based on the actual receiver type of the instantiation
* which may be null.
*/
abstract int getStartOffset(Class> receiverClass);
}
/**
* Graph data for a snippet or method substitution defined by a static method.
*/
static class StaticGraphData extends GraphData {
StaticGraphData(int startOffset, String originalMethod, SnippetParameterInfo info) {
super(startOffset, originalMethod, info);
}
@Override
int getStartOffset(Class> receiverClass) {
assert receiverClass == null : receiverClass;
return startOffset;
}
}
/**
* Graph data for a snippet defined by a virtual method. Method substitutions can't be virtual.
*/
static class VirtualGraphData extends GraphData {
private final Class> receiverClass;
private final VirtualGraphData next;
VirtualGraphData(int startOffset, String originalMethod, SnippetParameterInfo info, Class> receiverClass, VirtualGraphData next) {
super(startOffset, originalMethod, info);
this.receiverClass = receiverClass;
this.next = next;
}
@Override
int getStartOffset(Class> aClass) {
VirtualGraphData start = this;
while (start != null) {
if (start.receiverClass == aClass) {
return start.startOffset;
}
start = start.next;
}
throw GraalError.shouldNotReachHere("missing receiver type " + aClass); // ExcludeFromJacocoGeneratedReport
}
}
private final byte[] snippetEncoding;
private final Object[] snippetObjects;
private final NodeClass>[] snippetNodeClasses;
private final UnmodifiableEconomicMap graphDatas;
private final Map, SnippetResolvedJavaType> snippetTypes;
EncodedSnippets(byte[] snippetEncoding, Object[] snippetObjects, NodeClass>[] snippetNodeClasses, UnmodifiableEconomicMap graphDatas,
Map, SnippetResolvedJavaType> snippetTypes) {
this.snippetEncoding = snippetEncoding;
this.snippetObjects = snippetObjects;
this.snippetNodeClasses = snippetNodeClasses;
this.graphDatas = graphDatas;
this.snippetTypes = snippetTypes;
}
public NodeClass>[] getSnippetNodeClasses() {
return snippetNodeClasses;
}
public ResolvedJavaType lookupSnippetType(Class> clazz) {
SnippetResolvedJavaType type = snippetTypes.get(clazz);
if (type == null && isGraalClass(clazz)) {
// During image building, references to Graal classes from snippets are tracked.
// If a class isn't found in this path at runtime it means something was missed.
throw new GraalError("Missing Graal class " + clazz.getName());
}
return type;
}
public void visitImmutable(Consumer