< prev index next >

src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java

Print this page
rev 54697 : [mq]: 8218700


 367     public static JavaKind getHostWordKind() {
 368         return runtime().getHostJVMCIBackend().getCodeCache().getTarget().wordJavaKind;
 369     }
 370 
 371     protected final CompilerToVM compilerToVm;
 372 
 373     protected final HotSpotVMConfigStore configStore;
 374     protected final HotSpotVMConfig config;
 375     private final JVMCIBackend hostBackend;
 376 
 377     private final JVMCICompilerFactory compilerFactory;
 378     private final HotSpotJVMCICompilerFactory hsCompilerFactory;
 379     private volatile JVMCICompiler compiler;
 380     protected final HotSpotJVMCIReflection reflection;
 381 
 382     @NativeImageReinitialize private volatile boolean creatingCompiler;
 383 
 384     /**
 385      * Cache for speeding up {@link #fromClass(Class)}.
 386      */
 387     @NativeImageReinitialize private volatile ClassValue<WeakReference<HotSpotResolvedJavaType>> resolvedJavaType;


















 388 
 389     @NativeImageReinitialize private HashMap<Long, WeakReference<ResolvedJavaType>> resolvedJavaTypes;
 390 
 391     /**
 392      * Stores the value set by {@link #excludeFromJVMCICompilation(Module...)} so that it can
 393      * be read from the VM.
 394      */
 395     @SuppressWarnings("unused")//
 396     @NativeImageReinitialize private Module[] excludeFromJVMCICompilation;
 397 
 398 
 399     private final Map<Class<? extends Architecture>, JVMCIBackend> backends = new HashMap<>();
 400 
 401     private volatile List<HotSpotVMEventListener> vmEventListeners;
 402 
 403     private Iterable<HotSpotVMEventListener> getVmEventListeners() {
 404         if (vmEventListeners == null) {
 405             synchronized (this) {
 406                 if (vmEventListeners == null) {
 407                     vmEventListeners = JVMCIServiceLocator.getProviders(HotSpotVMEventListener.class);


 469     }
 470 
 471     HotSpotResolvedJavaType createClass(Class<?> javaClass) {
 472         if (javaClass.isPrimitive()) {
 473             return HotSpotResolvedPrimitiveType.forKind(JavaKind.fromJavaClass(javaClass));
 474         }
 475         if (IS_IN_NATIVE_IMAGE) {
 476             try {
 477                 return compilerToVm.lookupType(javaClass.getName().replace('.', '/'), null, true);
 478             } catch (ClassNotFoundException e) {
 479                 throw new JVMCIError(e);
 480             }
 481         }
 482         return compilerToVm.lookupClass(javaClass);
 483     }
 484 
 485     private HotSpotResolvedJavaType fromClass0(Class<?> javaClass) {
 486         if (resolvedJavaType == null) {
 487             synchronized (this) {
 488                 if (resolvedJavaType == null) {
 489                     resolvedJavaType = new ClassValue<WeakReference<HotSpotResolvedJavaType>>() {
 490                         @Override
 491                         protected WeakReference<HotSpotResolvedJavaType> computeValue(Class<?> type) {
 492                             return new WeakReference<>(createClass(type));
 493                         }
 494                     };
 495                 }
 496             }
 497         }
 498         HotSpotResolvedJavaType javaType = null;
 499         while (javaType == null) {
 500             WeakReference<HotSpotResolvedJavaType> type = resolvedJavaType.get(javaClass);
 501             javaType = type.get();
 502             if (javaType == null) {
 503                 /*
 504                  * If the referent has become null, clear out the current value and let computeValue
 505                  * above create a new value. Reload the value in a loop because in theory the
 506                  * WeakReference referent can be reclaimed at any point.
 507                  */
 508                 resolvedJavaType.remove(javaClass);
 509             }
 510         }
 511         return javaType;
 512     }
 513 
 514     /**
 515      * Gets the JVMCI mirror for a {@link Class} object.
 516      *
 517      * @return the {@link ResolvedJavaType} corresponding to {@code javaClass}
 518      */
 519     HotSpotResolvedJavaType fromClass(Class<?> javaClass) {
 520         if (javaClass == null) {
 521             return null;
 522         }
 523         return fromClass0(javaClass);
 524     }
 525 
 526     synchronized HotSpotResolvedObjectTypeImpl fromMetaspace(long klassPointer, String signature) {
 527         if (resolvedJavaTypes == null) {
 528             resolvedJavaTypes = new HashMap<>();
 529         }




 367     public static JavaKind getHostWordKind() {
 368         return runtime().getHostJVMCIBackend().getCodeCache().getTarget().wordJavaKind;
 369     }
 370 
 371     protected final CompilerToVM compilerToVm;
 372 
 373     protected final HotSpotVMConfigStore configStore;
 374     protected final HotSpotVMConfig config;
 375     private final JVMCIBackend hostBackend;
 376 
 377     private final JVMCICompilerFactory compilerFactory;
 378     private final HotSpotJVMCICompilerFactory hsCompilerFactory;
 379     private volatile JVMCICompiler compiler;
 380     protected final HotSpotJVMCIReflection reflection;
 381 
 382     @NativeImageReinitialize private volatile boolean creatingCompiler;
 383 
 384     /**
 385      * Cache for speeding up {@link #fromClass(Class)}.
 386      */
 387     @NativeImageReinitialize private volatile ClassValue<WeakReferenceHolder<HotSpotResolvedJavaType>> resolvedJavaType;
 388 
 389     /**
 390      * To avoid calling ClassValue.remove to refresh the weak reference, which
 391      * under certain circumstances can lead to an infinite loop, we use a
 392      * permanent holder with a mutable field that we refresh.
 393      */
 394     private static class WeakReferenceHolder<T> {
 395         private volatile WeakReference<T> ref;
 396         WeakReferenceHolder(T value) {
 397             set(value);
 398         }
 399         void set(T value) {
 400             ref = new WeakReference<T>(value);
 401         }
 402         T get() {
 403             return ref.get();
 404         }
 405     };
 406 
 407     @NativeImageReinitialize private HashMap<Long, WeakReference<ResolvedJavaType>> resolvedJavaTypes;
 408 
 409     /**
 410      * Stores the value set by {@link #excludeFromJVMCICompilation(Module...)} so that it can
 411      * be read from the VM.
 412      */
 413     @SuppressWarnings("unused")//
 414     @NativeImageReinitialize private Module[] excludeFromJVMCICompilation;
 415 
 416 
 417     private final Map<Class<? extends Architecture>, JVMCIBackend> backends = new HashMap<>();
 418 
 419     private volatile List<HotSpotVMEventListener> vmEventListeners;
 420 
 421     private Iterable<HotSpotVMEventListener> getVmEventListeners() {
 422         if (vmEventListeners == null) {
 423             synchronized (this) {
 424                 if (vmEventListeners == null) {
 425                     vmEventListeners = JVMCIServiceLocator.getProviders(HotSpotVMEventListener.class);


 487     }
 488 
 489     HotSpotResolvedJavaType createClass(Class<?> javaClass) {
 490         if (javaClass.isPrimitive()) {
 491             return HotSpotResolvedPrimitiveType.forKind(JavaKind.fromJavaClass(javaClass));
 492         }
 493         if (IS_IN_NATIVE_IMAGE) {
 494             try {
 495                 return compilerToVm.lookupType(javaClass.getName().replace('.', '/'), null, true);
 496             } catch (ClassNotFoundException e) {
 497                 throw new JVMCIError(e);
 498             }
 499         }
 500         return compilerToVm.lookupClass(javaClass);
 501     }
 502 
 503     private HotSpotResolvedJavaType fromClass0(Class<?> javaClass) {
 504         if (resolvedJavaType == null) {
 505             synchronized (this) {
 506                 if (resolvedJavaType == null) {
 507                     resolvedJavaType = new ClassValue<WeakReferenceHolder<HotSpotResolvedJavaType>>() {
 508                         @Override
 509                         protected WeakReferenceHolder<HotSpotResolvedJavaType> computeValue(Class<?> type) {
 510                             return new WeakReferenceHolder<>(createClass(type));
 511                         }
 512                     };
 513                 }
 514             }
 515         }
 516 
 517         WeakReferenceHolder<HotSpotResolvedJavaType> ref = resolvedJavaType.get(javaClass);
 518         HotSpotResolvedJavaType javaType = ref.get();

 519         if (javaType == null) {
 520             /*
 521              * If the referent has become null, create a new value and
 522              * update cached weak reference.

 523              */
 524             javaType = createClass(javaClass);
 525             ref.set(javaType);
 526         }
 527         return javaType;
 528     }
 529 
 530     /**
 531      * Gets the JVMCI mirror for a {@link Class} object.
 532      *
 533      * @return the {@link ResolvedJavaType} corresponding to {@code javaClass}
 534      */
 535     HotSpotResolvedJavaType fromClass(Class<?> javaClass) {
 536         if (javaClass == null) {
 537             return null;
 538         }
 539         return fromClass0(javaClass);
 540     }
 541 
 542     synchronized HotSpotResolvedObjectTypeImpl fromMetaspace(long klassPointer, String signature) {
 543         if (resolvedJavaTypes == null) {
 544             resolvedJavaTypes = new HashMap<>();
 545         }


< prev index next >