src/share/vm/runtime/reflection.hpp

changeset 435
a61af66fc99e
child 1100
c89f86385056
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/runtime/reflection.hpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,162 @@
     1.4 +/*
     1.5 + * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +// Class Reflection contains utility methods needed for implementing the
    1.29 +// reflection api.
    1.30 +//
    1.31 +// Used by functions in the JVM interface.
    1.32 +//
    1.33 +// NOTE that in JDK 1.4 most of reflection is now implemented in Java
    1.34 +// using dynamic bytecode generation. The Array class has not yet been
    1.35 +// rewritten using bytecodes; if it were, most of the rest of this
    1.36 +// class could go away, as well as a few more entry points in jvm.cpp.
    1.37 +
    1.38 +class FieldStream;
    1.39 +
    1.40 +class Reflection: public AllStatic {
    1.41 + private:
    1.42 +  // Access checking
    1.43 +  static bool reflect_check_access(klassOop field_class, AccessFlags acc, klassOop target_class, bool is_method_invoke, TRAPS);
    1.44 +
    1.45 +  // Conversion
    1.46 +  static klassOop basic_type_mirror_to_arrayklass(oop basic_type_mirror, TRAPS);
    1.47 +  static oop      basic_type_arrayklass_to_mirror(klassOop basic_type_arrayklass, TRAPS);
    1.48 +
    1.49 +  static objArrayHandle get_parameter_types(methodHandle method, int parameter_count, oop* return_type, TRAPS);
    1.50 +  static objArrayHandle get_exception_types(methodHandle method, TRAPS);
    1.51 +  // Creating new java.lang.reflect.xxx wrappers
    1.52 +  static Handle new_type(symbolHandle signature, KlassHandle k, TRAPS);
    1.53 +
    1.54 + public:
    1.55 +  // Constants defined by java reflection api classes
    1.56 +  enum SomeConstants {
    1.57 +    PUBLIC            = 0,
    1.58 +    DECLARED          = 1,
    1.59 +    MEMBER_PUBLIC     = 0,
    1.60 +    MEMBER_DECLARED   = 1,
    1.61 +    MAX_DIM           = 255
    1.62 +  };
    1.63 +
    1.64 +  // Boxing. Returns boxed value of appropriate type. Throws IllegalArgumentException.
    1.65 +  static oop box(jvalue* v, BasicType type, TRAPS);
    1.66 +  // Unboxing. Returns type code and sets value.
    1.67 +  static BasicType unbox_for_primitive(oop boxed_value, jvalue* value, TRAPS);
    1.68 +  static BasicType unbox_for_regular_object(oop boxed_value, jvalue* value);
    1.69 +
    1.70 +  // Widening of basic types. Throws IllegalArgumentException.
    1.71 +  static void widen(jvalue* value, BasicType current_type, BasicType wide_type, TRAPS);
    1.72 +
    1.73 +  // Reflective array access. Returns type code. Throws ArrayIndexOutOfBoundsException.
    1.74 +  static BasicType array_get(jvalue* value, arrayOop a, int index, TRAPS);
    1.75 +  static void      array_set(jvalue* value, arrayOop a, int index, BasicType value_type, TRAPS);
    1.76 +  // Returns mirror on array element type (NULL for basic type arrays and non-arrays).
    1.77 +  static oop       array_component_type(oop mirror, TRAPS);
    1.78 +
    1.79 +  // Object creation
    1.80 +  static arrayOop reflect_new_array(oop element_mirror, jint length, TRAPS);
    1.81 +  static arrayOop reflect_new_multi_array(oop element_mirror, typeArrayOop dimensions, TRAPS);
    1.82 +
    1.83 +  // Verification
    1.84 +  static bool     verify_class_access(klassOop current_class, klassOop new_class, bool classloader_only);
    1.85 +
    1.86 +  static bool     verify_field_access(klassOop current_class,
    1.87 +                                      klassOop resolved_class,
    1.88 +                                      klassOop field_class,
    1.89 +                                      AccessFlags access,
    1.90 +                                      bool classloader_only,
    1.91 +                                      bool protected_restriction = false);
    1.92 +  static bool     is_same_class_package(klassOop class1, klassOop class2);
    1.93 +
    1.94 +  static bool can_relax_access_check_for(
    1.95 +    klassOop accessor, klassOop accesee, bool classloader_only);
    1.96 +
    1.97 +  // inner class reflection
    1.98 +  static void check_for_inner_class(instanceKlassHandle outer, instanceKlassHandle inner, TRAPS);
    1.99 +
   1.100 +  //
   1.101 +  // Support for reflection based on dynamic bytecode generation (JDK 1.4)
   1.102 +  //
   1.103 +
   1.104 +  // Create a java.lang.reflect.Method object based on a method
   1.105 +  static oop new_method(methodHandle method, bool intern_name, bool for_constant_pool_access, TRAPS);
   1.106 +  // Create a java.lang.reflect.Constructor object based on a method
   1.107 +  static oop new_constructor(methodHandle method, TRAPS);
   1.108 +  // Create a java.lang.reflect.Field object based on a field descriptor
   1.109 +  static oop new_field(fieldDescriptor* fd, bool intern_name, TRAPS);
   1.110 +
   1.111 +  //---------------------------------------------------------------------------
   1.112 +  //
   1.113 +  // Support for old native code-based reflection (pre-JDK 1.4)
   1.114 +  //
   1.115 +  // NOTE: the method and constructor invocation code is still used
   1.116 +  // for startup time reasons; see reflectionCompat.hpp.
   1.117 +  //
   1.118 +  //---------------------------------------------------------------------------
   1.119 +
   1.120 +#ifdef SUPPORT_OLD_REFLECTION
   1.121 +private:
   1.122 +  // method resolution for invoke
   1.123 +  static methodHandle resolve_interface_call(instanceKlassHandle klass, methodHandle method, KlassHandle recv_klass, Handle receiver, TRAPS);
   1.124 +  // Method call (shared by invoke_method and invoke_constructor)
   1.125 +  static oop  invoke(instanceKlassHandle klass, methodHandle method, Handle receiver, bool override, objArrayHandle ptypes, BasicType rtype, objArrayHandle args, bool is_method_invoke, TRAPS);
   1.126 +
   1.127 +  // Narrowing of basic types. Used to create correct jvalues for
   1.128 +  // boolean, byte, char and short return return values from interpreter
   1.129 +  // which are returned as ints. Throws IllegalArgumentException.
   1.130 +  static void narrow(jvalue* value, BasicType narrow_type, TRAPS);
   1.131 +
   1.132 +  // Conversion
   1.133 +  static BasicType basic_type_mirror_to_basic_type(oop basic_type_mirror, TRAPS);
   1.134 +
   1.135 +  static bool match_parameter_types(methodHandle method, objArrayHandle types, int parameter_count, TRAPS);
   1.136 +  // Creating new java.lang.reflect.xxx wrappers
   1.137 +  static oop new_field(FieldStream* st, TRAPS);
   1.138 +
   1.139 +public:
   1.140 +  // Field lookup and verification.
   1.141 +  static bool      resolve_field(Handle field_mirror, Handle& receiver, fieldDescriptor* fd, bool check_final, TRAPS);
   1.142 +
   1.143 +  // Reflective field access. Returns type code. Throws IllegalArgumentException.
   1.144 +  static BasicType field_get(jvalue* value, fieldDescriptor* fd, Handle receiver);
   1.145 +  static void      field_set(jvalue* value, fieldDescriptor* fd, Handle receiver, BasicType value_type, TRAPS);
   1.146 +
   1.147 +  // Reflective lookup of fields. Returns java.lang.reflect.Field instances.
   1.148 +  static oop         reflect_field(oop mirror, symbolOop field_name, jint which, TRAPS);
   1.149 +  static objArrayOop reflect_fields(oop mirror, jint which, TRAPS);
   1.150 +
   1.151 +  // Reflective lookup of methods. Returns java.lang.reflect.Method instances.
   1.152 +  static oop         reflect_method(oop mirror, symbolHandle method_name, objArrayHandle types, jint which, TRAPS);
   1.153 +  static objArrayOop reflect_methods(oop mirror, jint which, TRAPS);
   1.154 +
   1.155 +  // Reflective lookup of constructors. Returns java.lang.reflect.Constructor instances.
   1.156 +  static oop         reflect_constructor(oop mirror, objArrayHandle types, jint which, TRAPS);
   1.157 +  static objArrayOop reflect_constructors(oop mirror, jint which, TRAPS);
   1.158 +
   1.159 +  // Method invokation through java.lang.reflect.Method
   1.160 +  static oop      invoke_method(oop method_mirror, Handle receiver, objArrayHandle args, TRAPS);
   1.161 +  // Method invokation through java.lang.reflect.Constructor
   1.162 +  static oop      invoke_constructor(oop method_mirror, objArrayHandle args, TRAPS);
   1.163 +#endif /* SUPPORT_OLD_REFLECTION */
   1.164 +
   1.165 +};

mercurial