1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/runtime/reflection.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,148 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_RUNTIME_REFLECTION_HPP 1.29 +#define SHARE_VM_RUNTIME_REFLECTION_HPP 1.30 + 1.31 +#include "oops/oop.hpp" 1.32 +#include "runtime/fieldDescriptor.hpp" 1.33 +#include "utilities/accessFlags.hpp" 1.34 +#include "utilities/growableArray.hpp" 1.35 + 1.36 +// Class Reflection contains utility methods needed for implementing the 1.37 +// reflection api. 1.38 +// 1.39 +// Used by functions in the JVM interface. 1.40 +// 1.41 +// NOTE that in JDK 1.4 most of reflection is now implemented in Java 1.42 +// using dynamic bytecode generation. The Array class has not yet been 1.43 +// rewritten using bytecodes; if it were, most of the rest of this 1.44 +// class could go away, as well as a few more entry points in jvm.cpp. 1.45 + 1.46 +class FieldStream; 1.47 + 1.48 +class Reflection: public AllStatic { 1.49 + private: 1.50 + // Access checking 1.51 + static bool reflect_check_access(Klass* field_class, AccessFlags acc, Klass* target_class, bool is_method_invoke, TRAPS); 1.52 + 1.53 + // Conversion 1.54 + static Klass* basic_type_mirror_to_arrayklass(oop basic_type_mirror, TRAPS); 1.55 + static oop basic_type_arrayklass_to_mirror(Klass* basic_type_arrayklass, TRAPS); 1.56 + 1.57 + static objArrayHandle get_parameter_types(methodHandle method, int parameter_count, oop* return_type, TRAPS); 1.58 + static objArrayHandle get_exception_types(methodHandle method, TRAPS); 1.59 + // Creating new java.lang.reflect.xxx wrappers 1.60 + static Handle new_type(Symbol* signature, KlassHandle k, TRAPS); 1.61 + 1.62 + public: 1.63 + // Constants defined by java reflection api classes 1.64 + enum SomeConstants { 1.65 + PUBLIC = 0, 1.66 + DECLARED = 1, 1.67 + MEMBER_PUBLIC = 0, 1.68 + MEMBER_DECLARED = 1, 1.69 + MAX_DIM = 255 1.70 + }; 1.71 + 1.72 + // Boxing. Returns boxed value of appropriate type. Throws IllegalArgumentException. 1.73 + static oop box(jvalue* v, BasicType type, TRAPS); 1.74 + // Unboxing. Returns type code and sets value. 1.75 + static BasicType unbox_for_primitive(oop boxed_value, jvalue* value, TRAPS); 1.76 + static BasicType unbox_for_regular_object(oop boxed_value, jvalue* value); 1.77 + 1.78 + // Widening of basic types. Throws IllegalArgumentException. 1.79 + static void widen(jvalue* value, BasicType current_type, BasicType wide_type, TRAPS); 1.80 + 1.81 + // Reflective array access. Returns type code. Throws ArrayIndexOutOfBoundsException. 1.82 + static BasicType array_get(jvalue* value, arrayOop a, int index, TRAPS); 1.83 + static void array_set(jvalue* value, arrayOop a, int index, BasicType value_type, TRAPS); 1.84 + // Returns mirror on array element type (NULL for basic type arrays and non-arrays). 1.85 + static oop array_component_type(oop mirror, TRAPS); 1.86 + 1.87 + // Object creation 1.88 + static arrayOop reflect_new_array(oop element_mirror, jint length, TRAPS); 1.89 + static arrayOop reflect_new_multi_array(oop element_mirror, typeArrayOop dimensions, TRAPS); 1.90 + 1.91 + // Verification 1.92 + static bool verify_class_access(Klass* current_class, Klass* new_class, bool classloader_only); 1.93 + 1.94 + static bool verify_field_access(Klass* current_class, 1.95 + Klass* resolved_class, 1.96 + Klass* field_class, 1.97 + AccessFlags access, 1.98 + bool classloader_only, 1.99 + bool protected_restriction = false); 1.100 + static bool is_same_class_package(Klass* class1, Klass* class2); 1.101 + static bool is_same_package_member(Klass* class1, Klass* class2, TRAPS); 1.102 + 1.103 + static bool can_relax_access_check_for( 1.104 + Klass* accessor, Klass* accesee, bool classloader_only); 1.105 + 1.106 + // inner class reflection 1.107 + // raise an ICCE unless the required relationship can be proven to hold 1.108 + // If inner_is_member, require the inner to be a member of the outer. 1.109 + // If !inner_is_member, require the inner to be anonymous (a non-member). 1.110 + // Caller is responsible for figuring out in advance which case must be true. 1.111 + static void check_for_inner_class(instanceKlassHandle outer, instanceKlassHandle inner, 1.112 + bool inner_is_member, TRAPS); 1.113 + 1.114 + // 1.115 + // Support for reflection based on dynamic bytecode generation (JDK 1.4) 1.116 + // 1.117 + 1.118 + // Create a java.lang.reflect.Method object based on a method 1.119 + static oop new_method(methodHandle method, bool intern_name, bool for_constant_pool_access, TRAPS); 1.120 + // Create a java.lang.reflect.Constructor object based on a method 1.121 + static oop new_constructor(methodHandle method, TRAPS); 1.122 + // Create a java.lang.reflect.Field object based on a field descriptor 1.123 + static oop new_field(fieldDescriptor* fd, bool intern_name, TRAPS); 1.124 + // Create a java.lang.reflect.Parameter object based on a 1.125 + // MethodParameterElement 1.126 + static oop new_parameter(Handle method, int index, Symbol* sym, 1.127 + int flags, TRAPS); 1.128 + 1.129 +private: 1.130 + // method resolution for invoke 1.131 + static methodHandle resolve_interface_call(instanceKlassHandle klass, methodHandle method, KlassHandle recv_klass, Handle receiver, TRAPS); 1.132 + // Method call (shared by invoke_method and invoke_constructor) 1.133 + static oop invoke(instanceKlassHandle klass, methodHandle method, Handle receiver, bool override, objArrayHandle ptypes, BasicType rtype, objArrayHandle args, bool is_method_invoke, TRAPS); 1.134 + 1.135 + // Narrowing of basic types. Used to create correct jvalues for 1.136 + // boolean, byte, char and short return return values from interpreter 1.137 + // which are returned as ints. Throws IllegalArgumentException. 1.138 + static void narrow(jvalue* value, BasicType narrow_type, TRAPS); 1.139 + 1.140 + // Conversion 1.141 + static BasicType basic_type_mirror_to_basic_type(oop basic_type_mirror, TRAPS); 1.142 + 1.143 +public: 1.144 + // Method invokation through java.lang.reflect.Method 1.145 + static oop invoke_method(oop method_mirror, Handle receiver, objArrayHandle args, TRAPS); 1.146 + // Method invokation through java.lang.reflect.Constructor 1.147 + static oop invoke_constructor(oop method_mirror, objArrayHandle args, TRAPS); 1.148 + 1.149 +}; 1.150 + 1.151 +#endif // SHARE_VM_RUNTIME_REFLECTION_HPP