< prev index next >

src/java.base/share/classes/jdk/internal/reflect/NativeMethodAccessorImpl.java

Print this page




  30 
  31 /** Used only for the first few invocations of a Method; afterward,
  32     switches to bytecode-based implementation */
  33 
  34 class NativeMethodAccessorImpl extends MethodAccessorImpl {
  35     private final Method method;
  36     private DelegatingMethodAccessorImpl parent;
  37     private int numInvocations;
  38 
  39     NativeMethodAccessorImpl(Method method) {
  40         this.method = method;
  41     }
  42 
  43     public Object invoke(Object obj, Object[] args)
  44         throws IllegalArgumentException, InvocationTargetException
  45     {
  46         // We can't inflate methods belonging to vm-anonymous classes because
  47         // that kind of class can't be referred to by name, hence can't be
  48         // found from the generated bytecode.
  49         if (++numInvocations > ReflectionFactory.inflationThreshold()
  50                 && !ReflectUtil.isVMAnonymousClass(method.getDeclaringClass())) {
  51             MethodAccessorImpl acc = (MethodAccessorImpl)
  52                 new MethodAccessorGenerator().
  53                     generateMethod(method.getDeclaringClass(),
  54                                    method.getName(),
  55                                    method.getParameterTypes(),
  56                                    method.getReturnType(),
  57                                    method.getExceptionTypes(),
  58                                    method.getModifiers());
  59             parent.setDelegate(acc);
  60         }
  61 
  62         return invoke0(method, obj, args);
  63     }
  64 
  65     void setParent(DelegatingMethodAccessorImpl parent) {
  66         this.parent = parent;
  67     }
  68 
  69     private static native Object invoke0(Method m, Object obj, Object[] args);
  70 }


  30 
  31 /** Used only for the first few invocations of a Method; afterward,
  32     switches to bytecode-based implementation */
  33 
  34 class NativeMethodAccessorImpl extends MethodAccessorImpl {
  35     private final Method method;
  36     private DelegatingMethodAccessorImpl parent;
  37     private int numInvocations;
  38 
  39     NativeMethodAccessorImpl(Method method) {
  40         this.method = method;
  41     }
  42 
  43     public Object invoke(Object obj, Object[] args)
  44         throws IllegalArgumentException, InvocationTargetException
  45     {
  46         // We can't inflate methods belonging to vm-anonymous classes because
  47         // that kind of class can't be referred to by name, hence can't be
  48         // found from the generated bytecode.
  49         if (++numInvocations > ReflectionFactory.inflationThreshold()
  50                 && !method.getDeclaringClass().isHidden()) {
  51             MethodAccessorImpl acc = (MethodAccessorImpl)
  52                 new MethodAccessorGenerator().
  53                     generateMethod(method.getDeclaringClass(),
  54                                    method.getName(),
  55                                    method.getParameterTypes(),
  56                                    method.getReturnType(),
  57                                    method.getExceptionTypes(),
  58                                    method.getModifiers());
  59             parent.setDelegate(acc);
  60         }
  61 
  62         return invoke0(method, obj, args);
  63     }
  64 
  65     void setParent(DelegatingMethodAccessorImpl parent) {
  66         this.parent = parent;
  67     }
  68 
  69     private static native Object invoke0(Method m, Object obj, Object[] args);
  70 }
< prev index next >