Mercurial > hg > graal-jvmci-8
comparison jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java @ 22704:ce4bec6db0b2
narrow type of HotSpotResolvedJavaMethodImpl.toJavaCache to Executable
author | Andreas Woess <andreas.woess@oracle.com> |
---|---|
date | Fri, 23 Oct 2015 13:24:08 +0200 |
parents | 1bbd4a7c274b |
children | 8017f84cce74 |
comparison
equal
deleted
inserted
replaced
22703:f190cf6fb28e | 22704:ce4bec6db0b2 |
---|---|
27 import static jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod.Options.UseProfilingInformation; | 27 import static jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod.Options.UseProfilingInformation; |
28 import static jdk.vm.ci.hotspot.HotSpotVMConfig.config; | 28 import static jdk.vm.ci.hotspot.HotSpotVMConfig.config; |
29 import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE; | 29 import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE; |
30 | 30 |
31 import java.lang.annotation.Annotation; | 31 import java.lang.annotation.Annotation; |
32 import java.lang.reflect.Constructor; | 32 import java.lang.reflect.Executable; |
33 import java.lang.reflect.InvocationTargetException; | 33 import java.lang.reflect.InvocationTargetException; |
34 import java.lang.reflect.Member; | |
35 import java.lang.reflect.Method; | 34 import java.lang.reflect.Method; |
36 import java.lang.reflect.Modifier; | 35 import java.lang.reflect.Modifier; |
37 import java.lang.reflect.Type; | 36 import java.lang.reflect.Type; |
38 import java.util.HashMap; | 37 import java.util.HashMap; |
39 import java.util.Map; | 38 import java.util.Map; |
73 private final HotSpotResolvedObjectTypeImpl holder; | 72 private final HotSpotResolvedObjectTypeImpl holder; |
74 private final HotSpotConstantPool constantPool; | 73 private final HotSpotConstantPool constantPool; |
75 private final HotSpotSignature signature; | 74 private final HotSpotSignature signature; |
76 private HotSpotMethodData methodData; | 75 private HotSpotMethodData methodData; |
77 private byte[] code; | 76 private byte[] code; |
78 private Member toJavaCache; | 77 private Executable toJavaCache; |
79 | 78 |
80 /** | 79 /** |
81 * Gets the holder of a HotSpot metaspace method native object. | 80 * Gets the holder of a HotSpot metaspace method native object. |
82 * | 81 * |
83 * @param metaspaceMethod a metaspace Method object | 82 * @param metaspaceMethod a metaspace Method object |
456 return constantPool; | 455 return constantPool; |
457 } | 456 } |
458 | 457 |
459 @Override | 458 @Override |
460 public Annotation[][] getParameterAnnotations() { | 459 public Annotation[][] getParameterAnnotations() { |
461 if (isConstructor()) { | 460 Executable javaMethod = toJava(); |
462 Constructor<?> javaConstructor = toJavaConstructor(); | |
463 return javaConstructor == null ? null : javaConstructor.getParameterAnnotations(); | |
464 } | |
465 Method javaMethod = toJava(); | |
466 return javaMethod == null ? null : javaMethod.getParameterAnnotations(); | 461 return javaMethod == null ? null : javaMethod.getParameterAnnotations(); |
467 } | 462 } |
468 | 463 |
469 @Override | 464 @Override |
470 public Annotation[] getAnnotations() { | 465 public Annotation[] getAnnotations() { |
471 if (isConstructor()) { | 466 Executable javaMethod = toJava(); |
472 Constructor<?> javaConstructor = toJavaConstructor(); | |
473 return javaConstructor == null ? new Annotation[0] : javaConstructor.getAnnotations(); | |
474 } | |
475 Method javaMethod = toJava(); | |
476 return javaMethod == null ? new Annotation[0] : javaMethod.getAnnotations(); | 467 return javaMethod == null ? new Annotation[0] : javaMethod.getAnnotations(); |
477 } | 468 } |
478 | 469 |
479 @Override | 470 @Override |
480 public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { | 471 public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { |
481 if (isConstructor()) { | 472 Executable javaMethod = toJava(); |
482 Constructor<?> javaConstructor = toJavaConstructor(); | |
483 return javaConstructor == null ? null : javaConstructor.getAnnotation(annotationClass); | |
484 } | |
485 Method javaMethod = toJava(); | |
486 return javaMethod == null ? null : javaMethod.getAnnotation(annotationClass); | 473 return javaMethod == null ? null : javaMethod.getAnnotation(annotationClass); |
487 } | 474 } |
488 | 475 |
489 public boolean isDefault() { | 476 public boolean isDefault() { |
490 if (isConstructor()) { | 477 if (isConstructor()) { |
495 return ((getModifiers() & mask) == Modifier.PUBLIC) && getDeclaringClass().isInterface(); | 482 return ((getModifiers() & mask) == Modifier.PUBLIC) && getDeclaringClass().isInterface(); |
496 } | 483 } |
497 | 484 |
498 @Override | 485 @Override |
499 public Type[] getGenericParameterTypes() { | 486 public Type[] getGenericParameterTypes() { |
500 if (isConstructor()) { | 487 Executable javaMethod = toJava(); |
501 Constructor<?> javaConstructor = toJavaConstructor(); | |
502 return javaConstructor == null ? null : javaConstructor.getGenericParameterTypes(); | |
503 } | |
504 Method javaMethod = toJava(); | |
505 return javaMethod == null ? null : javaMethod.getGenericParameterTypes(); | 488 return javaMethod == null ? null : javaMethod.getGenericParameterTypes(); |
506 } | 489 } |
507 | 490 |
508 public Class<?>[] signatureToTypes() { | 491 public Class<?>[] signatureToTypes() { |
509 Signature sig = getSignature(); | 492 Signature sig = getSignature(); |
515 result[i] = resolvedParameterType.mirror(); | 498 result[i] = resolvedParameterType.mirror(); |
516 } | 499 } |
517 return result; | 500 return result; |
518 } | 501 } |
519 | 502 |
520 private Method toJava() { | 503 private Executable toJava() { |
521 if (toJavaCache != null) { | 504 if (toJavaCache != null) { |
522 return (Method) toJavaCache; | 505 return toJavaCache; |
523 } | 506 } |
524 try { | 507 try { |
525 Method result = holder.mirror().getDeclaredMethod(name, signatureToTypes()); | 508 Class<?>[] parameterTypes = signatureToTypes(); |
526 toJavaCache = result; | 509 Executable result = isConstructor() ? holder.mirror().getDeclaredConstructor(parameterTypes) : holder.mirror().getDeclaredMethod(name, parameterTypes); |
527 return result; | |
528 } catch (NoSuchMethodException | NoClassDefFoundError e) { | |
529 return null; | |
530 } | |
531 } | |
532 | |
533 private Constructor<?> toJavaConstructor() { | |
534 if (toJavaCache != null) { | |
535 return (Constructor<?>) toJavaCache; | |
536 } | |
537 try { | |
538 Constructor<?> result = holder.mirror().getDeclaredConstructor(signatureToTypes()); | |
539 toJavaCache = result; | 510 toJavaCache = result; |
540 return result; | 511 return result; |
541 } catch (NoSuchMethodException | NoClassDefFoundError e) { | 512 } catch (NoSuchMethodException | NoClassDefFoundError e) { |
542 return null; | 513 return null; |
543 } | 514 } |
706 } | 677 } |
707 | 678 |
708 @Override | 679 @Override |
709 public JavaConstant invoke(JavaConstant receiver, JavaConstant[] arguments) { | 680 public JavaConstant invoke(JavaConstant receiver, JavaConstant[] arguments) { |
710 assert !isConstructor(); | 681 assert !isConstructor(); |
711 Method javaMethod = toJava(); | 682 Method javaMethod = (Method) toJava(); |
712 javaMethod.setAccessible(true); | 683 javaMethod.setAccessible(true); |
713 | 684 |
714 Object[] objArguments = new Object[arguments.length]; | 685 Object[] objArguments = new Object[arguments.length]; |
715 for (int i = 0; i < arguments.length; i++) { | 686 for (int i = 0; i < arguments.length; i++) { |
716 objArguments[i] = HotSpotObjectConstantImpl.asBoxedValue(arguments[i]); | 687 objArguments[i] = HotSpotObjectConstantImpl.asBoxedValue(arguments[i]); |