Mercurial > hg > graal-jvmci-8
comparison jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java @ 23789:0cb263db490f
use MethodParameters attribute instead of depending on -g option for sanity checks (JDK-8168915)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 04 Nov 2016 14:22:47 +0100 |
parents | aaed278a9cf1 |
children | 224f43824e2b |
comparison
equal
deleted
inserted
replaced
23788:e804aec381cd | 23789:0cb263db490f |
---|---|
31 import static jdk.vm.ci.hotspot.HotSpotVMConfig.config; | 31 import static jdk.vm.ci.hotspot.HotSpotVMConfig.config; |
32 import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE; | 32 import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE; |
33 | 33 |
34 import java.lang.annotation.Annotation; | 34 import java.lang.annotation.Annotation; |
35 import java.lang.reflect.Executable; | 35 import java.lang.reflect.Executable; |
36 import java.lang.reflect.Method; | |
36 import java.lang.reflect.Modifier; | 37 import java.lang.reflect.Modifier; |
37 import java.lang.reflect.Type; | 38 import java.lang.reflect.Type; |
39 import java.util.Arrays; | |
38 import java.util.HashMap; | 40 import java.util.HashMap; |
39 import java.util.Map; | 41 import java.util.Map; |
40 | 42 |
41 import jdk.vm.ci.common.JVMCIError; | 43 import jdk.vm.ci.common.JVMCIError; |
42 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.Option; | 44 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.Option; |
460 public ConstantPool getConstantPool() { | 462 public ConstantPool getConstantPool() { |
461 return constantPool; | 463 return constantPool; |
462 } | 464 } |
463 | 465 |
464 @Override | 466 @Override |
467 public Parameter[] getParameters() { | |
468 Executable javaMethod = toJava(); | |
469 if (javaMethod == null) { | |
470 return null; | |
471 } | |
472 | |
473 java.lang.reflect.Parameter[] javaParameters = javaMethod.getParameters(); | |
474 Parameter[] res = new Parameter[javaParameters.length]; | |
475 for (int i = 0; i < res.length; i++) { | |
476 java.lang.reflect.Parameter src = javaParameters[i]; | |
477 res[i] = new Parameter(src.getName(), src.getModifiers(), this, i); | |
478 } | |
479 return res; | |
480 } | |
481 | |
482 @Override | |
465 public Annotation[][] getParameterAnnotations() { | 483 public Annotation[][] getParameterAnnotations() { |
466 Executable javaMethod = toJava(); | 484 Executable javaMethod = toJava(); |
467 return javaMethod == null ? null : javaMethod.getParameterAnnotations(); | 485 return javaMethod == null ? null : javaMethod.getParameterAnnotations(); |
468 } | 486 } |
469 | 487 |
529 result[i] = resolvedParameterType.mirror(); | 547 result[i] = resolvedParameterType.mirror(); |
530 } | 548 } |
531 return result; | 549 return result; |
532 } | 550 } |
533 | 551 |
552 private static Method searchMethods(Method[] methods, String name, Class<?> returnType, Class<?>[] parameterTypes) { | |
553 for (Method m : methods) { | |
554 if (m.getName().equals(name) && returnType.equals(m.getReturnType()) && Arrays.equals(m.getParameterTypes(), parameterTypes)) { | |
555 return m; | |
556 } | |
557 } | |
558 return null; | |
559 } | |
560 | |
534 private Executable toJava() { | 561 private Executable toJava() { |
535 if (toJavaCache != null) { | 562 if (toJavaCache != null) { |
536 return toJavaCache; | 563 return toJavaCache; |
537 } | 564 } |
538 try { | 565 try { |
539 Class<?>[] parameterTypes = signatureToTypes(); | 566 Class<?>[] parameterTypes = signatureToTypes(); |
540 Executable result = isConstructor() ? holder.mirror().getDeclaredConstructor(parameterTypes) : holder.mirror().getDeclaredMethod(name, parameterTypes); | 567 Class<?> returnType = ((HotSpotResolvedJavaType) getSignature().getReturnType(holder).resolve(holder)).mirror(); |
568 | |
569 Executable result; | |
570 if (isConstructor()) { | |
571 result = holder.mirror().getDeclaredConstructor(parameterTypes); | |
572 } else { | |
573 // Do not use Method.getDeclaredMethod() as it can return a bridge method | |
574 // when this.isBridge() is false and vice versa. | |
575 result = searchMethods(holder.mirror().getDeclaredMethods(), name, returnType, parameterTypes); | |
576 } | |
541 toJavaCache = result; | 577 toJavaCache = result; |
542 return result; | 578 return result; |
543 } catch (NoSuchMethodException | NoClassDefFoundError e) { | 579 } catch (NoSuchMethodException | NoClassDefFoundError e) { |
544 return null; | 580 return null; |
545 } | 581 } |