< prev index next >

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

Print this page




  78 import jdk.vm.ci.hotspot.HotSpotCompilationRequest;
  79 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
  80 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
  81 import jdk.vm.ci.hotspot.HotSpotResolvedJavaType;
  82 import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
  83 import jdk.vm.ci.hotspot.HotSpotVMConfigStore;
  84 import jdk.vm.ci.meta.JavaKind;
  85 import jdk.vm.ci.meta.MetaAccessProvider;
  86 import jdk.vm.ci.meta.ResolvedJavaMethod;
  87 import jdk.vm.ci.meta.ResolvedJavaType;
  88 import jdk.vm.ci.runtime.JVMCI;
  89 import jdk.vm.ci.runtime.JVMCIBackend;
  90 
  91 //JaCoCo Exclude
  92 
  93 /**
  94  * Singleton class holding the instance of the {@link GraalRuntime}.
  95  */
  96 public final class HotSpotGraalRuntime implements HotSpotGraalRuntimeProvider {
  97 


  98     private static boolean checkArrayIndexScaleInvariants(MetaAccessProvider metaAccess) {
  99         assert metaAccess.getArrayIndexScale(JavaKind.Byte) == 1;
 100         assert metaAccess.getArrayIndexScale(JavaKind.Boolean) == 1;
 101         assert metaAccess.getArrayIndexScale(JavaKind.Char) == 2;
 102         assert metaAccess.getArrayIndexScale(JavaKind.Short) == 2;
 103         assert metaAccess.getArrayIndexScale(JavaKind.Int) == 4;
 104         assert metaAccess.getArrayIndexScale(JavaKind.Long) == 8;
 105         assert metaAccess.getArrayIndexScale(JavaKind.Float) == 4;
 106         assert metaAccess.getArrayIndexScale(JavaKind.Double) == 8;
 107         return true;
 108     }
 109 
 110     private final String runtimeName;
 111     private final String compilerConfigurationName;
 112     private final HotSpotBackend hostBackend;
 113     private final GlobalMetrics metricValues = new GlobalMetrics();
 114     private final List<SnippetCounter.Group> snippetCounterGroups;
 115     private final HotSpotGC garbageCollector;
 116 
 117     private final EconomicMap<Class<? extends Architecture>, HotSpotBackend> backends = EconomicMap.create(Equivalence.IDENTITY);


 142         HotSpotVMConfigStore store = jvmciRuntime.getConfigStore();
 143         config = GeneratePIC.getValue(initialOptions) ? new AOTGraalHotSpotVMConfig(store) : new GraalHotSpotVMConfig(store);
 144 
 145         // Only set HotSpotPrintInlining if it still has its default value (false).
 146         if (GraalOptions.HotSpotPrintInlining.getValue(initialOptions) == false && config.printInlining) {
 147             optionsRef.set(new OptionValues(initialOptions, HotSpotPrintInlining, true));
 148         } else {
 149             optionsRef.set(initialOptions);
 150         }
 151         OptionValues options = optionsRef.get();
 152 
 153         garbageCollector = getSelectedGC();
 154 
 155         outputDirectory = new DiagnosticsOutputDirectory(options);
 156         compilationProblemsPerAction = new EnumMap<>(ExceptionAction.class);
 157         snippetCounterGroups = GraalOptions.SnippetCounters.getValue(options) ? new ArrayList<>() : null;
 158         CompilerConfiguration compilerConfiguration = compilerConfigurationFactory.createCompilerConfiguration();
 159         compilerConfigurationName = compilerConfigurationFactory.getName();
 160 
 161         compiler = new HotSpotGraalCompiler(jvmciRuntime, this, options);
 162         management = GraalServices.loadSingle(HotSpotGraalManagementRegistration.class, false);
 163         if (management != null) {
 164             management.initialize(this);




 165         }
 166 
 167         BackendMap backendMap = compilerConfigurationFactory.createBackendMap();
 168 
 169         JVMCIBackend hostJvmciBackend = jvmciRuntime.getHostJVMCIBackend();
 170         Architecture hostArchitecture = hostJvmciBackend.getTarget().arch;
 171         try (InitTimer t = timer("create backend:", hostArchitecture)) {
 172             HotSpotBackendFactory factory = backendMap.getBackendFactory(hostArchitecture);
 173             if (factory == null) {
 174                 throw new GraalError("No backend available for host architecture \"%s\"", hostArchitecture);
 175             }
 176             hostBackend = registerBackend(factory.createBackend(this, compilerConfiguration, jvmciRuntime, null));
 177         }
 178 
 179         for (JVMCIBackend jvmciBackend : jvmciRuntime.getJVMCIBackends().values()) {
 180             if (jvmciBackend == hostJvmciBackend) {
 181                 continue;
 182             }
 183 
 184             Architecture gpuArchitecture = jvmciBackend.getTarget().arch;


 554         EconomicSet<Class<?>> found = loaders.resolve(className, failures);
 555         if (found.isEmpty()) {
 556             ClassNotFoundException cause = failures.isEmpty() ? new ClassNotFoundException(className) : failures.iterator().next();
 557             throw new Exception("Cannot find class " + className + " to schedule recompilation", cause);
 558         }
 559         for (Class<?> clazz : found) {
 560             ResolvedJavaType type = JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess().lookupJavaType(clazz);
 561             for (ResolvedJavaMethod method : type.getDeclaredMethods()) {
 562                 if (methodName.equals(method.getName()) && method instanceof HotSpotResolvedJavaMethod) {
 563                     HotSpotResolvedJavaMethod hotSpotMethod = (HotSpotResolvedJavaMethod) method;
 564                     dumpMethod(hotSpotMethod, filter, host, port);
 565                 }
 566             }
 567         }
 568     }
 569 
 570     private void dumpMethod(HotSpotResolvedJavaMethod hotSpotMethod, String filter, String host, int port) throws Exception {
 571         EconomicMap<OptionKey<?>, Object> extra = EconomicMap.create();
 572         extra.put(DebugOptions.Dump, filter);
 573         extra.put(DebugOptions.PrintGraphHost, host);
 574         extra.put(DebugOptions.PrintBinaryGraphPort, port);
 575         OptionValues compileOptions = new OptionValues(getOptions(), extra);
 576         compiler.compileMethod(new HotSpotCompilationRequest(hotSpotMethod, -1, 0L), false, compileOptions);
 577     }
 578 
 579     public Object invokeManagementAction(String actionName, Object[] params) throws Exception {
 580         if ("dumpMethod".equals(actionName)) {
 581             if (params.length != 0 && params[0] instanceof HotSpotResolvedJavaMethod) {
 582                 HotSpotResolvedJavaMethod method = param(params, 0, "method", HotSpotResolvedJavaMethod.class, null);
 583                 String filter = param(params, 1, "filter", String.class, ":3");
 584                 String host = param(params, 2, "host", String.class, "localhost");
 585                 Number port = param(params, 3, "port", Number.class, 4445);
 586                 dumpMethod(method, filter, host, port.intValue());
 587             } else {
 588                 String className = param(params, 0, "className", String.class, null);
 589                 String methodName = param(params, 1, "methodName", String.class, null);
 590                 String filter = param(params, 2, "filter", String.class, ":3");
 591                 String host = param(params, 3, "host", String.class, "localhost");
 592                 Number port = param(params, 4, "port", Number.class, 4445);
 593                 dumpMethod(className, methodName, filter, host, port.intValue());
 594             }


  78 import jdk.vm.ci.hotspot.HotSpotCompilationRequest;
  79 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
  80 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
  81 import jdk.vm.ci.hotspot.HotSpotResolvedJavaType;
  82 import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
  83 import jdk.vm.ci.hotspot.HotSpotVMConfigStore;
  84 import jdk.vm.ci.meta.JavaKind;
  85 import jdk.vm.ci.meta.MetaAccessProvider;
  86 import jdk.vm.ci.meta.ResolvedJavaMethod;
  87 import jdk.vm.ci.meta.ResolvedJavaType;
  88 import jdk.vm.ci.runtime.JVMCI;
  89 import jdk.vm.ci.runtime.JVMCIBackend;
  90 
  91 //JaCoCo Exclude
  92 
  93 /**
  94  * Singleton class holding the instance of the {@link GraalRuntime}.
  95  */
  96 public final class HotSpotGraalRuntime implements HotSpotGraalRuntimeProvider {
  97 
  98     private static final boolean IS_AOT = Boolean.getBoolean("com.oracle.graalvm.isaot");
  99 
 100     private static boolean checkArrayIndexScaleInvariants(MetaAccessProvider metaAccess) {
 101         assert metaAccess.getArrayIndexScale(JavaKind.Byte) == 1;
 102         assert metaAccess.getArrayIndexScale(JavaKind.Boolean) == 1;
 103         assert metaAccess.getArrayIndexScale(JavaKind.Char) == 2;
 104         assert metaAccess.getArrayIndexScale(JavaKind.Short) == 2;
 105         assert metaAccess.getArrayIndexScale(JavaKind.Int) == 4;
 106         assert metaAccess.getArrayIndexScale(JavaKind.Long) == 8;
 107         assert metaAccess.getArrayIndexScale(JavaKind.Float) == 4;
 108         assert metaAccess.getArrayIndexScale(JavaKind.Double) == 8;
 109         return true;
 110     }
 111 
 112     private final String runtimeName;
 113     private final String compilerConfigurationName;
 114     private final HotSpotBackend hostBackend;
 115     private final GlobalMetrics metricValues = new GlobalMetrics();
 116     private final List<SnippetCounter.Group> snippetCounterGroups;
 117     private final HotSpotGC garbageCollector;
 118 
 119     private final EconomicMap<Class<? extends Architecture>, HotSpotBackend> backends = EconomicMap.create(Equivalence.IDENTITY);


 144         HotSpotVMConfigStore store = jvmciRuntime.getConfigStore();
 145         config = GeneratePIC.getValue(initialOptions) ? new AOTGraalHotSpotVMConfig(store) : new GraalHotSpotVMConfig(store);
 146 
 147         // Only set HotSpotPrintInlining if it still has its default value (false).
 148         if (GraalOptions.HotSpotPrintInlining.getValue(initialOptions) == false && config.printInlining) {
 149             optionsRef.set(new OptionValues(initialOptions, HotSpotPrintInlining, true));
 150         } else {
 151             optionsRef.set(initialOptions);
 152         }
 153         OptionValues options = optionsRef.get();
 154 
 155         garbageCollector = getSelectedGC();
 156 
 157         outputDirectory = new DiagnosticsOutputDirectory(options);
 158         compilationProblemsPerAction = new EnumMap<>(ExceptionAction.class);
 159         snippetCounterGroups = GraalOptions.SnippetCounters.getValue(options) ? new ArrayList<>() : null;
 160         CompilerConfiguration compilerConfiguration = compilerConfigurationFactory.createCompilerConfiguration();
 161         compilerConfigurationName = compilerConfigurationFactory.getName();
 162 
 163         compiler = new HotSpotGraalCompiler(jvmciRuntime, this, options);
 164         if (IS_AOT) {
 165             management = null;
 166         } else {
 167             management = GraalServices.loadSingle(HotSpotGraalManagementRegistration.class, false);
 168             if (management != null) {
 169                 management.initialize(this);
 170             }
 171         }
 172 
 173         BackendMap backendMap = compilerConfigurationFactory.createBackendMap();
 174 
 175         JVMCIBackend hostJvmciBackend = jvmciRuntime.getHostJVMCIBackend();
 176         Architecture hostArchitecture = hostJvmciBackend.getTarget().arch;
 177         try (InitTimer t = timer("create backend:", hostArchitecture)) {
 178             HotSpotBackendFactory factory = backendMap.getBackendFactory(hostArchitecture);
 179             if (factory == null) {
 180                 throw new GraalError("No backend available for host architecture \"%s\"", hostArchitecture);
 181             }
 182             hostBackend = registerBackend(factory.createBackend(this, compilerConfiguration, jvmciRuntime, null));
 183         }
 184 
 185         for (JVMCIBackend jvmciBackend : jvmciRuntime.getJVMCIBackends().values()) {
 186             if (jvmciBackend == hostJvmciBackend) {
 187                 continue;
 188             }
 189 
 190             Architecture gpuArchitecture = jvmciBackend.getTarget().arch;


 560         EconomicSet<Class<?>> found = loaders.resolve(className, failures);
 561         if (found.isEmpty()) {
 562             ClassNotFoundException cause = failures.isEmpty() ? new ClassNotFoundException(className) : failures.iterator().next();
 563             throw new Exception("Cannot find class " + className + " to schedule recompilation", cause);
 564         }
 565         for (Class<?> clazz : found) {
 566             ResolvedJavaType type = JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess().lookupJavaType(clazz);
 567             for (ResolvedJavaMethod method : type.getDeclaredMethods()) {
 568                 if (methodName.equals(method.getName()) && method instanceof HotSpotResolvedJavaMethod) {
 569                     HotSpotResolvedJavaMethod hotSpotMethod = (HotSpotResolvedJavaMethod) method;
 570                     dumpMethod(hotSpotMethod, filter, host, port);
 571                 }
 572             }
 573         }
 574     }
 575 
 576     private void dumpMethod(HotSpotResolvedJavaMethod hotSpotMethod, String filter, String host, int port) throws Exception {
 577         EconomicMap<OptionKey<?>, Object> extra = EconomicMap.create();
 578         extra.put(DebugOptions.Dump, filter);
 579         extra.put(DebugOptions.PrintGraphHost, host);
 580         extra.put(DebugOptions.PrintGraphPort, port);
 581         OptionValues compileOptions = new OptionValues(getOptions(), extra);
 582         compiler.compileMethod(new HotSpotCompilationRequest(hotSpotMethod, -1, 0L), false, compileOptions);
 583     }
 584 
 585     public Object invokeManagementAction(String actionName, Object[] params) throws Exception {
 586         if ("dumpMethod".equals(actionName)) {
 587             if (params.length != 0 && params[0] instanceof HotSpotResolvedJavaMethod) {
 588                 HotSpotResolvedJavaMethod method = param(params, 0, "method", HotSpotResolvedJavaMethod.class, null);
 589                 String filter = param(params, 1, "filter", String.class, ":3");
 590                 String host = param(params, 2, "host", String.class, "localhost");
 591                 Number port = param(params, 3, "port", Number.class, 4445);
 592                 dumpMethod(method, filter, host, port.intValue());
 593             } else {
 594                 String className = param(params, 0, "className", String.class, null);
 595                 String methodName = param(params, 1, "methodName", String.class, null);
 596                 String filter = param(params, 2, "filter", String.class, ":3");
 597                 String host = param(params, 3, "host", String.class, "localhost");
 598                 Number port = param(params, 4, "port", Number.class, 4445);
 599                 dumpMethod(className, methodName, filter, host, port.intValue());
 600             }
< prev index next >