29 |
29 |
30 import java.io.IOException; |
30 import java.io.IOException; |
31 import java.io.OutputStream; |
31 import java.io.OutputStream; |
32 import java.io.PrintStream; |
32 import java.io.PrintStream; |
33 import java.io.Serializable; |
33 import java.io.Serializable; |
34 |
|
35 import java.lang.invoke.CallSite; |
34 import java.lang.invoke.CallSite; |
36 import java.lang.invoke.ConstantCallSite; |
35 import java.lang.invoke.ConstantCallSite; |
37 import java.lang.invoke.MethodHandle; |
36 import java.lang.invoke.MethodHandle; |
38 import java.lang.module.ModuleDescriptor.Requires; |
|
39 import java.lang.ref.WeakReference; |
37 import java.lang.ref.WeakReference; |
40 |
|
41 import java.util.ArrayList; |
38 import java.util.ArrayList; |
42 import java.util.Collections; |
39 import java.util.Collections; |
43 import java.util.HashMap; |
40 import java.util.HashMap; |
44 import java.util.HashSet; |
|
45 import java.util.List; |
41 import java.util.List; |
46 import java.util.Map; |
42 import java.util.Map; |
47 import java.util.Objects; |
43 import java.util.Objects; |
48 import java.util.ServiceLoader; |
44 import java.util.ServiceLoader; |
49 import java.util.function.Predicate; |
45 import java.util.function.Predicate; |
50 |
|
51 import jdk.internal.misc.Unsafe; |
|
52 |
46 |
53 import jdk.vm.ci.code.Architecture; |
47 import jdk.vm.ci.code.Architecture; |
54 import jdk.vm.ci.code.CompilationRequestResult; |
48 import jdk.vm.ci.code.CompilationRequestResult; |
55 import jdk.vm.ci.code.CompiledCode; |
49 import jdk.vm.ci.code.CompiledCode; |
56 import jdk.vm.ci.code.InstalledCode; |
50 import jdk.vm.ci.code.InstalledCode; |
185 } |
179 } |
186 // Ensures JVMCIRuntime::_HotSpotJVMCIRuntime_instance is |
180 // Ensures JVMCIRuntime::_HotSpotJVMCIRuntime_instance is |
187 // initialized. |
181 // initialized. |
188 JVMCI.getRuntime(); |
182 JVMCI.getRuntime(); |
189 } |
183 } |
190 // Make sure all the primitive box caches are populated (required to properly materialize boxed primitives |
184 // Make sure all the primitive box caches are populated (required to properly |
|
185 // materialize boxed primitives |
191 // during deoptimization). |
186 // during deoptimization). |
192 Object[] boxCaches = { Boolean.valueOf(false), Byte.valueOf((byte)0), Short.valueOf((short) 0), Character.valueOf((char) 0), Integer.valueOf(0), Long.valueOf(0) }; |
187 Boolean.valueOf(false); |
|
188 Byte.valueOf((byte) 0); |
|
189 Short.valueOf((short) 0); |
|
190 Character.valueOf((char) 0); |
|
191 Integer.valueOf(0); |
|
192 Long.valueOf(0); |
193 } |
193 } |
194 } |
194 } |
195 return result; |
195 return result; |
196 } |
196 } |
197 |
197 |
336 } |
336 } |
337 } |
337 } |
338 |
338 |
339 private static HotSpotJVMCIBackendFactory findFactory(String architecture) { |
339 private static HotSpotJVMCIBackendFactory findFactory(String architecture) { |
340 Iterable<HotSpotJVMCIBackendFactory> factories = getHotSpotJVMCIBackendFactories(); |
340 Iterable<HotSpotJVMCIBackendFactory> factories = getHotSpotJVMCIBackendFactories(); |
341 assert factories != null : "sanity"; |
341 assert factories != null : "sanity"; |
342 for (HotSpotJVMCIBackendFactory factory : factories) { |
342 for (HotSpotJVMCIBackendFactory factory : factories) { |
343 if (factory.getArchitecture().equalsIgnoreCase(architecture)) { |
343 if (factory.getArchitecture().equalsIgnoreCase(architecture)) { |
344 return factory; |
344 return factory; |
345 } |
345 } |
346 } |
346 } |
389 * Cache for speeding up {@link #fromClass(Class)}. |
389 * Cache for speeding up {@link #fromClass(Class)}. |
390 */ |
390 */ |
391 @NativeImageReinitialize private volatile ClassValue<WeakReferenceHolder<HotSpotResolvedJavaType>> resolvedJavaType; |
391 @NativeImageReinitialize private volatile ClassValue<WeakReferenceHolder<HotSpotResolvedJavaType>> resolvedJavaType; |
392 |
392 |
393 /** |
393 /** |
394 * To avoid calling ClassValue.remove to refresh the weak reference, which |
394 * To avoid calling ClassValue.remove to refresh the weak reference, which under certain |
395 * under certain circumstances can lead to an infinite loop, we use a |
395 * circumstances can lead to an infinite loop, we use a permanent holder with a mutable field |
396 * permanent holder with a mutable field that we refresh. |
396 * that we refresh. |
397 */ |
397 */ |
398 private static class WeakReferenceHolder<T> { |
398 private static class WeakReferenceHolder<T> { |
399 private volatile WeakReference<T> ref; |
399 private volatile WeakReference<T> ref; |
|
400 |
400 WeakReferenceHolder(T value) { |
401 WeakReferenceHolder(T value) { |
401 set(value); |
402 set(value); |
402 } |
403 } |
|
404 |
403 void set(T value) { |
405 void set(T value) { |
404 ref = new WeakReference<T>(value); |
406 ref = new WeakReference<>(value); |
405 } |
407 } |
|
408 |
406 T get() { |
409 T get() { |
407 return ref.get(); |
410 return ref.get(); |
408 } |
411 } |
409 }; |
412 } |
410 |
413 |
411 @NativeImageReinitialize private HashMap<Long, WeakReference<ResolvedJavaType>> resolvedJavaTypes; |
414 @NativeImageReinitialize private HashMap<Long, WeakReference<ResolvedJavaType>> resolvedJavaTypes; |
412 |
415 |
413 /** |
416 /** |
414 * Stores the value set by {@link #excludeFromJVMCICompilation(Module...)} so that it can |
417 * Stores the value set by {@link #excludeFromJVMCICompilation(Module...)} so that it can be |
415 * be read from the VM. |
418 * read from the VM. |
416 */ |
419 */ |
417 @SuppressWarnings("unused")// |
420 @SuppressWarnings("unused")// |
418 @NativeImageReinitialize private Module[] excludeFromJVMCICompilation; |
421 @NativeImageReinitialize private Module[] excludeFromJVMCICompilation; |
419 |
|
420 |
422 |
421 private final Map<Class<? extends Architecture>, JVMCIBackend> backends = new HashMap<>(); |
423 private final Map<Class<? extends Architecture>, JVMCIBackend> backends = new HashMap<>(); |
422 |
424 |
423 private volatile List<HotSpotVMEventListener> vmEventListeners; |
425 private volatile List<HotSpotVMEventListener> vmEventListeners; |
424 |
426 |
506 |
508 |
507 private HotSpotResolvedJavaType fromClass0(Class<?> javaClass) { |
509 private HotSpotResolvedJavaType fromClass0(Class<?> javaClass) { |
508 if (resolvedJavaType == null) { |
510 if (resolvedJavaType == null) { |
509 synchronized (this) { |
511 synchronized (this) { |
510 if (resolvedJavaType == null) { |
512 if (resolvedJavaType == null) { |
511 resolvedJavaType = new ClassValue<WeakReferenceHolder<HotSpotResolvedJavaType>>() { |
513 resolvedJavaType = new ClassValue<>() { |
512 @Override |
514 @Override |
513 protected WeakReferenceHolder<HotSpotResolvedJavaType> computeValue(Class<?> type) { |
515 protected WeakReferenceHolder<HotSpotResolvedJavaType> computeValue(Class<?> type) { |
514 return new WeakReferenceHolder<>(createClass(type)); |
516 return new WeakReferenceHolder<>(createClass(type)); |
515 } |
517 } |
516 }; |
518 }; |
520 |
522 |
521 WeakReferenceHolder<HotSpotResolvedJavaType> ref = resolvedJavaType.get(javaClass); |
523 WeakReferenceHolder<HotSpotResolvedJavaType> ref = resolvedJavaType.get(javaClass); |
522 HotSpotResolvedJavaType javaType = ref.get(); |
524 HotSpotResolvedJavaType javaType = ref.get(); |
523 if (javaType == null) { |
525 if (javaType == null) { |
524 /* |
526 /* |
525 * If the referent has become null, create a new value and |
527 * If the referent has become null, create a new value and update cached weak reference. |
526 * update cached weak reference. |
|
527 */ |
528 */ |
528 javaType = createClass(javaClass); |
529 javaType = createClass(javaClass); |
529 ref.set(javaType); |
530 ref.set(javaType); |
530 } |
531 } |
531 return javaType; |
532 return javaType; |
589 * |
590 * |
590 * @param compilerLeafClasses classes in the leaves of the module graph comprising the JVMCI |
591 * @param compilerLeafClasses classes in the leaves of the module graph comprising the JVMCI |
591 * compiler. |
592 * compiler. |
592 */ |
593 */ |
593 public Predicate<ResolvedJavaType> getIntrinsificationTrustPredicate(Class<?>... compilerLeafClasses) { |
594 public Predicate<ResolvedJavaType> getIntrinsificationTrustPredicate(Class<?>... compilerLeafClasses) { |
594 return new Predicate<ResolvedJavaType>() { |
595 return new Predicate<>() { |
595 @Override |
596 @Override |
596 public boolean test(ResolvedJavaType type) { |
597 public boolean test(ResolvedJavaType type) { |
597 if (type instanceof HotSpotResolvedObjectTypeImpl) { |
598 if (type instanceof HotSpotResolvedObjectTypeImpl) { |
598 HotSpotResolvedObjectTypeImpl hsType = (HotSpotResolvedObjectTypeImpl) type; |
599 HotSpotResolvedObjectTypeImpl hsType = (HotSpotResolvedObjectTypeImpl) type; |
599 return compilerToVm.isTrustedForIntrinsics(hsType); |
600 return compilerToVm.isTrustedForIntrinsics(hsType); |