< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/meta/HotSpotGraphBuilderPlugins.java

Print this page




  30 import static org.graalvm.compiler.hotspot.meta.HotSpotAOTProfilingPlugin.Options.TieredAOT;
  31 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.JAVA_THREAD_THREAD_OBJECT_LOCATION;
  32 import static org.graalvm.compiler.java.BytecodeParserOptions.InlineDuringParsing;
  33 
  34 import java.lang.invoke.ConstantCallSite;
  35 import java.lang.invoke.MutableCallSite;
  36 import java.lang.invoke.VolatileCallSite;
  37 import java.lang.reflect.Array;
  38 import java.math.BigInteger;
  39 import java.util.zip.CRC32;
  40 
  41 import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
  42 import org.graalvm.compiler.bytecode.BytecodeProvider;
  43 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider;
  44 import org.graalvm.compiler.core.common.type.ObjectStamp;
  45 import org.graalvm.compiler.core.common.type.StampFactory;
  46 import org.graalvm.compiler.core.common.type.TypeReference;
  47 import org.graalvm.compiler.debug.GraalError;
  48 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
  49 import org.graalvm.compiler.hotspot.nodes.CurrentJavaThreadNode;

  50 import org.graalvm.compiler.hotspot.replacements.AESCryptSubstitutions;
  51 import org.graalvm.compiler.hotspot.replacements.ArraysSupportSubstitutions;
  52 import org.graalvm.compiler.hotspot.replacements.BigIntegerSubstitutions;
  53 import org.graalvm.compiler.hotspot.replacements.CRC32CSubstitutions;
  54 import org.graalvm.compiler.hotspot.replacements.CRC32Substitutions;
  55 import org.graalvm.compiler.hotspot.replacements.CallSiteTargetNode;
  56 import org.graalvm.compiler.hotspot.replacements.CipherBlockChainingSubstitutions;
  57 import org.graalvm.compiler.hotspot.replacements.ClassGetHubNode;
  58 import org.graalvm.compiler.hotspot.replacements.CounterModeSubstitutions;
  59 import org.graalvm.compiler.hotspot.replacements.DigestBaseSubstitutions;
  60 import org.graalvm.compiler.hotspot.replacements.HotSpotArraySubstitutions;
  61 import org.graalvm.compiler.hotspot.replacements.HotSpotClassSubstitutions;
  62 import org.graalvm.compiler.hotspot.replacements.IdentityHashCodeNode;
  63 import org.graalvm.compiler.hotspot.replacements.ObjectCloneNode;
  64 import org.graalvm.compiler.hotspot.replacements.ObjectSubstitutions;
  65 import org.graalvm.compiler.hotspot.replacements.ReflectionGetCallerClassNode;
  66 import org.graalvm.compiler.hotspot.replacements.ReflectionSubstitutions;
  67 import org.graalvm.compiler.hotspot.replacements.SHA2Substitutions;
  68 import org.graalvm.compiler.hotspot.replacements.SHA5Substitutions;
  69 import org.graalvm.compiler.hotspot.replacements.SHASubstitutions;


 130      */
 131     public static Plugins create(CompilerConfiguration compilerConfiguration, GraalHotSpotVMConfig config, HotSpotWordTypes wordTypes, MetaAccessProvider metaAccess,
 132                     ConstantReflectionProvider constantReflection, SnippetReflectionProvider snippetReflection, ForeignCallsProvider foreignCalls, ReplacementsImpl replacements,
 133                     OptionValues options) {
 134         InvocationPlugins invocationPlugins = new HotSpotInvocationPlugins(config, compilerConfiguration);
 135 
 136         Plugins plugins = new Plugins(invocationPlugins);
 137         NodeIntrinsificationProvider nodeIntrinsificationProvider = new NodeIntrinsificationProvider(metaAccess, snippetReflection, foreignCalls, wordTypes);
 138         HotSpotWordOperationPlugin wordOperationPlugin = new HotSpotWordOperationPlugin(snippetReflection, wordTypes);
 139         HotSpotNodePlugin nodePlugin = new HotSpotNodePlugin(wordOperationPlugin, config, wordTypes);
 140 
 141         plugins.appendTypePlugin(nodePlugin);
 142         plugins.appendNodePlugin(nodePlugin);
 143         if (!GeneratePIC.getValue(options)) {
 144             plugins.appendNodePlugin(new MethodHandlePlugin(constantReflection.getMethodHandleAccess(), true));
 145         }
 146         plugins.appendInlineInvokePlugin(replacements);
 147         if (InlineDuringParsing.getValue(options)) {
 148             plugins.appendInlineInvokePlugin(new InlineDuringParsingPlugin());
 149         }
 150 
 151         if (GeneratePIC.getValue(options)) {
 152             plugins.setClassInitializationPlugin(new HotSpotClassInitializationPlugin());
 153             if (TieredAOT.getValue(options)) {
 154                 plugins.setProfilingPlugin(new HotSpotAOTProfilingPlugin());
 155             }
 156         }
 157 
 158         invocationPlugins.defer(new Runnable() {
 159 
 160             @Override
 161             public void run() {
 162                 BytecodeProvider replacementBytecodeProvider = replacements.getDefaultReplacementBytecodeProvider();
 163                 registerObjectPlugins(invocationPlugins, options, config, replacementBytecodeProvider);
 164                 registerClassPlugins(plugins, config, replacementBytecodeProvider);
 165                 registerSystemPlugins(invocationPlugins, foreignCalls);
 166                 registerThreadPlugins(invocationPlugins, metaAccess, wordTypes, config, replacementBytecodeProvider);
 167                 if (!GeneratePIC.getValue(options)) {
 168                     registerCallSitePlugins(invocationPlugins);
 169                 }
 170                 registerReflectionPlugins(invocationPlugins, replacementBytecodeProvider);


 398             }
 399         });
 400     }
 401 
 402     private static void registerArrayPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
 403         Registration r = new Registration(plugins, Array.class, bytecodeProvider);
 404         r.setAllowOverwrite(true);
 405         r.registerMethodSubstitution(HotSpotArraySubstitutions.class, "newInstance", Class.class, int.class);
 406     }
 407 
 408     private static void registerStringPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
 409         if (JavaVersionUtil.JAVA_SPEC > 8) {
 410             final Registration utf16r = new Registration(plugins, "java.lang.StringUTF16", bytecodeProvider);
 411             utf16r.registerMethodSubstitution(StringUTF16Substitutions.class, "toBytes", char[].class, int.class, int.class);
 412             utf16r.registerMethodSubstitution(StringUTF16Substitutions.class, "getChars", byte[].class, int.class, int.class, char[].class, int.class);
 413         }
 414     }
 415 
 416     private static void registerThreadPlugins(InvocationPlugins plugins, MetaAccessProvider metaAccess, WordTypes wordTypes, GraalHotSpotVMConfig config, BytecodeProvider bytecodeProvider) {
 417         Registration r = new Registration(plugins, Thread.class, bytecodeProvider);
 418         r.register0("currentThread", new InvocationPlugin() {
 419             @Override
 420             public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
 421                 CurrentJavaThreadNode thread = b.add(new CurrentJavaThreadNode(wordTypes.getWordKind()));
 422                 ValueNode offset = b.add(ConstantNode.forLong(config.threadObjectOffset));
 423                 AddressNode address = b.add(new OffsetAddressNode(thread, offset));
 424                 // JavaThread::_threadObj is never compressed
 425                 ObjectStamp stamp = StampFactory.objectNonNull(TypeReference.create(b.getAssumptions(), metaAccess.lookupJavaType(Thread.class)));
 426                 b.addPush(JavaKind.Object, new ReadNode(address, JAVA_THREAD_THREAD_OBJECT_LOCATION, stamp, BarrierType.NONE));
 427                 return true;
 428             }
 429         });
 430 
 431         r.registerMethodSubstitution(ThreadSubstitutions.class, "isInterrupted", Receiver.class, boolean.class);








 432     }
 433 
 434     public static final String aesEncryptName;
 435     public static final String aesDecryptName;
 436 
 437     public static final String reflectionClass;
 438     public static final String constantPoolClass;
 439 
 440     static {
 441         if (JavaVersionUtil.JAVA_SPEC <= 8) {
 442             aesEncryptName = "encryptBlock";
 443             aesDecryptName = "decryptBlock";
 444             reflectionClass = "sun.reflect.Reflection";
 445             constantPoolClass = "sun.reflect.ConstantPool";
 446         } else {
 447             aesEncryptName = "implEncryptBlock";
 448             aesDecryptName = "implDecryptBlock";
 449             reflectionClass = "jdk.internal.reflect.Reflection";
 450             constantPoolClass = "jdk.internal.reflect.ConstantPool";
 451         }




  30 import static org.graalvm.compiler.hotspot.meta.HotSpotAOTProfilingPlugin.Options.TieredAOT;
  31 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.JAVA_THREAD_THREAD_OBJECT_LOCATION;
  32 import static org.graalvm.compiler.java.BytecodeParserOptions.InlineDuringParsing;
  33 
  34 import java.lang.invoke.ConstantCallSite;
  35 import java.lang.invoke.MutableCallSite;
  36 import java.lang.invoke.VolatileCallSite;
  37 import java.lang.reflect.Array;
  38 import java.math.BigInteger;
  39 import java.util.zip.CRC32;
  40 
  41 import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
  42 import org.graalvm.compiler.bytecode.BytecodeProvider;
  43 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider;
  44 import org.graalvm.compiler.core.common.type.ObjectStamp;
  45 import org.graalvm.compiler.core.common.type.StampFactory;
  46 import org.graalvm.compiler.core.common.type.TypeReference;
  47 import org.graalvm.compiler.debug.GraalError;
  48 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
  49 import org.graalvm.compiler.hotspot.nodes.CurrentJavaThreadNode;
  50 import org.graalvm.compiler.hotspot.replacements.ContinuationSubstitutions;
  51 import org.graalvm.compiler.hotspot.replacements.AESCryptSubstitutions;
  52 import org.graalvm.compiler.hotspot.replacements.ArraysSupportSubstitutions;
  53 import org.graalvm.compiler.hotspot.replacements.BigIntegerSubstitutions;
  54 import org.graalvm.compiler.hotspot.replacements.CRC32CSubstitutions;
  55 import org.graalvm.compiler.hotspot.replacements.CRC32Substitutions;
  56 import org.graalvm.compiler.hotspot.replacements.CallSiteTargetNode;
  57 import org.graalvm.compiler.hotspot.replacements.CipherBlockChainingSubstitutions;
  58 import org.graalvm.compiler.hotspot.replacements.ClassGetHubNode;
  59 import org.graalvm.compiler.hotspot.replacements.CounterModeSubstitutions;
  60 import org.graalvm.compiler.hotspot.replacements.DigestBaseSubstitutions;
  61 import org.graalvm.compiler.hotspot.replacements.HotSpotArraySubstitutions;
  62 import org.graalvm.compiler.hotspot.replacements.HotSpotClassSubstitutions;
  63 import org.graalvm.compiler.hotspot.replacements.IdentityHashCodeNode;
  64 import org.graalvm.compiler.hotspot.replacements.ObjectCloneNode;
  65 import org.graalvm.compiler.hotspot.replacements.ObjectSubstitutions;
  66 import org.graalvm.compiler.hotspot.replacements.ReflectionGetCallerClassNode;
  67 import org.graalvm.compiler.hotspot.replacements.ReflectionSubstitutions;
  68 import org.graalvm.compiler.hotspot.replacements.SHA2Substitutions;
  69 import org.graalvm.compiler.hotspot.replacements.SHA5Substitutions;
  70 import org.graalvm.compiler.hotspot.replacements.SHASubstitutions;


 131      */
 132     public static Plugins create(CompilerConfiguration compilerConfiguration, GraalHotSpotVMConfig config, HotSpotWordTypes wordTypes, MetaAccessProvider metaAccess,
 133                     ConstantReflectionProvider constantReflection, SnippetReflectionProvider snippetReflection, ForeignCallsProvider foreignCalls, ReplacementsImpl replacements,
 134                     OptionValues options) {
 135         InvocationPlugins invocationPlugins = new HotSpotInvocationPlugins(config, compilerConfiguration);
 136 
 137         Plugins plugins = new Plugins(invocationPlugins);
 138         NodeIntrinsificationProvider nodeIntrinsificationProvider = new NodeIntrinsificationProvider(metaAccess, snippetReflection, foreignCalls, wordTypes);
 139         HotSpotWordOperationPlugin wordOperationPlugin = new HotSpotWordOperationPlugin(snippetReflection, wordTypes);
 140         HotSpotNodePlugin nodePlugin = new HotSpotNodePlugin(wordOperationPlugin, config, wordTypes);
 141 
 142         plugins.appendTypePlugin(nodePlugin);
 143         plugins.appendNodePlugin(nodePlugin);
 144         if (!GeneratePIC.getValue(options)) {
 145             plugins.appendNodePlugin(new MethodHandlePlugin(constantReflection.getMethodHandleAccess(), true));
 146         }
 147         plugins.appendInlineInvokePlugin(replacements);
 148         if (InlineDuringParsing.getValue(options)) {
 149             plugins.appendInlineInvokePlugin(new InlineDuringParsingPlugin());
 150         }
 151         registerContinuationPlugins(invocationPlugins, foreignCalls, replacements.getDefaultReplacementBytecodeProvider());
 152         if (GeneratePIC.getValue(options)) {
 153             plugins.setClassInitializationPlugin(new HotSpotClassInitializationPlugin());
 154             if (TieredAOT.getValue(options)) {
 155                 plugins.setProfilingPlugin(new HotSpotAOTProfilingPlugin());
 156             }
 157         }
 158 
 159         invocationPlugins.defer(new Runnable() {
 160 
 161             @Override
 162             public void run() {
 163                 BytecodeProvider replacementBytecodeProvider = replacements.getDefaultReplacementBytecodeProvider();
 164                 registerObjectPlugins(invocationPlugins, options, config, replacementBytecodeProvider);
 165                 registerClassPlugins(plugins, config, replacementBytecodeProvider);
 166                 registerSystemPlugins(invocationPlugins, foreignCalls);
 167                 registerThreadPlugins(invocationPlugins, metaAccess, wordTypes, config, replacementBytecodeProvider);
 168                 if (!GeneratePIC.getValue(options)) {
 169                     registerCallSitePlugins(invocationPlugins);
 170                 }
 171                 registerReflectionPlugins(invocationPlugins, replacementBytecodeProvider);


 399             }
 400         });
 401     }
 402 
 403     private static void registerArrayPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
 404         Registration r = new Registration(plugins, Array.class, bytecodeProvider);
 405         r.setAllowOverwrite(true);
 406         r.registerMethodSubstitution(HotSpotArraySubstitutions.class, "newInstance", Class.class, int.class);
 407     }
 408 
 409     private static void registerStringPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
 410         if (JavaVersionUtil.JAVA_SPEC > 8) {
 411             final Registration utf16r = new Registration(plugins, "java.lang.StringUTF16", bytecodeProvider);
 412             utf16r.registerMethodSubstitution(StringUTF16Substitutions.class, "toBytes", char[].class, int.class, int.class);
 413             utf16r.registerMethodSubstitution(StringUTF16Substitutions.class, "getChars", byte[].class, int.class, int.class, char[].class, int.class);
 414         }
 415     }
 416 
 417     private static void registerThreadPlugins(InvocationPlugins plugins, MetaAccessProvider metaAccess, WordTypes wordTypes, GraalHotSpotVMConfig config, BytecodeProvider bytecodeProvider) {
 418         Registration r = new Registration(plugins, Thread.class, bytecodeProvider);
 419         r.register0("currentThread0", new InvocationPlugin() {
 420             @Override
 421             public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
 422                 CurrentJavaThreadNode thread = b.add(new CurrentJavaThreadNode(wordTypes.getWordKind()));
 423                 ValueNode offset = b.add(ConstantNode.forLong(config.threadObjectOffset));
 424                 AddressNode address = b.add(new OffsetAddressNode(thread, offset));
 425                 // JavaThread::_threadObj is never compressed
 426                 ObjectStamp stamp = StampFactory.objectNonNull(TypeReference.create(b.getAssumptions(), metaAccess.lookupJavaType(Thread.class)));
 427                 b.addPush(JavaKind.Object, new ReadNode(address, JAVA_THREAD_THREAD_OBJECT_LOCATION, stamp, BarrierType.NONE));
 428                 return true;
 429             }
 430         });
 431 
 432         r.registerMethodSubstitution(ThreadSubstitutions.class, "isInterrupted", Receiver.class, boolean.class);
 433     }
 434 
 435     private static void registerContinuationPlugins(InvocationPlugins plugins,  ForeignCallsProvider foreignCalls, BytecodeProvider bytecodeProvider) {
 436         Registration r1 = new Registration(plugins, Continuation.class, bytecodeProvider);
 437         r1.registerMethodSubstitution(ContinuationSubstitutions.class, "getSP");
 438         r1.register1("doContinue", Receiver.class, new ForeignCallPlugin(foreignCalls, ContinuationSubstitutions.CONTINUATION_DO_CONTINUE));
 439         r1.register1("doYield", int.class, new ForeignCallPlugin(foreignCalls, ContinuationSubstitutions.CONTINUATION_YIELD));
 440         r1.registerMethodSubstitution(ContinuationSubstitutions.class, "runLevel");
 441     }
 442 
 443     public static final String aesEncryptName;
 444     public static final String aesDecryptName;
 445 
 446     public static final String reflectionClass;
 447     public static final String constantPoolClass;
 448 
 449     static {
 450         if (JavaVersionUtil.JAVA_SPEC <= 8) {
 451             aesEncryptName = "encryptBlock";
 452             aesDecryptName = "decryptBlock";
 453             reflectionClass = "sun.reflect.Reflection";
 454             constantPoolClass = "sun.reflect.ConstantPool";
 455         } else {
 456             aesEncryptName = "implEncryptBlock";
 457             aesDecryptName = "implDecryptBlock";
 458             reflectionClass = "jdk.internal.reflect.Reflection";
 459             constantPoolClass = "jdk.internal.reflect.ConstantPool";
 460         }


< prev index next >