src/share/vm/runtime/reflection.hpp

Fri, 28 Mar 2014 10:12:48 -0700

author
vlivanov
date
Fri, 28 Mar 2014 10:12:48 -0700
changeset 6527
f47fa50d9b9c
parent 6198
55fb97c4c58d
child 6876
710a3c8b516e
permissions
-rw-r--r--

8035887: VM crashes trying to force inlining the recursive call
Reviewed-by: kvn, twisti

duke@435 1 /*
mikael@6198 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_RUNTIME_REFLECTION_HPP
stefank@2314 26 #define SHARE_VM_RUNTIME_REFLECTION_HPP
stefank@2314 27
stefank@2314 28 #include "oops/oop.hpp"
stefank@2314 29 #include "runtime/fieldDescriptor.hpp"
stefank@2314 30 #include "utilities/accessFlags.hpp"
stefank@2314 31 #include "utilities/growableArray.hpp"
stefank@2314 32
duke@435 33 // Class Reflection contains utility methods needed for implementing the
duke@435 34 // reflection api.
duke@435 35 //
duke@435 36 // Used by functions in the JVM interface.
duke@435 37 //
duke@435 38 // NOTE that in JDK 1.4 most of reflection is now implemented in Java
duke@435 39 // using dynamic bytecode generation. The Array class has not yet been
duke@435 40 // rewritten using bytecodes; if it were, most of the rest of this
duke@435 41 // class could go away, as well as a few more entry points in jvm.cpp.
duke@435 42
duke@435 43 class FieldStream;
duke@435 44
duke@435 45 class Reflection: public AllStatic {
duke@435 46 private:
duke@435 47 // Access checking
coleenp@4037 48 static bool reflect_check_access(Klass* field_class, AccessFlags acc, Klass* target_class, bool is_method_invoke, TRAPS);
duke@435 49
duke@435 50 // Conversion
coleenp@4037 51 static Klass* basic_type_mirror_to_arrayklass(oop basic_type_mirror, TRAPS);
coleenp@4037 52 static oop basic_type_arrayklass_to_mirror(Klass* basic_type_arrayklass, TRAPS);
duke@435 53
duke@435 54 static objArrayHandle get_parameter_types(methodHandle method, int parameter_count, oop* return_type, TRAPS);
duke@435 55 static objArrayHandle get_exception_types(methodHandle method, TRAPS);
duke@435 56 // Creating new java.lang.reflect.xxx wrappers
coleenp@2497 57 static Handle new_type(Symbol* signature, KlassHandle k, TRAPS);
duke@435 58
duke@435 59 public:
duke@435 60 // Constants defined by java reflection api classes
duke@435 61 enum SomeConstants {
duke@435 62 PUBLIC = 0,
duke@435 63 DECLARED = 1,
duke@435 64 MEMBER_PUBLIC = 0,
duke@435 65 MEMBER_DECLARED = 1,
duke@435 66 MAX_DIM = 255
duke@435 67 };
duke@435 68
duke@435 69 // Boxing. Returns boxed value of appropriate type. Throws IllegalArgumentException.
duke@435 70 static oop box(jvalue* v, BasicType type, TRAPS);
duke@435 71 // Unboxing. Returns type code and sets value.
duke@435 72 static BasicType unbox_for_primitive(oop boxed_value, jvalue* value, TRAPS);
duke@435 73 static BasicType unbox_for_regular_object(oop boxed_value, jvalue* value);
duke@435 74
duke@435 75 // Widening of basic types. Throws IllegalArgumentException.
duke@435 76 static void widen(jvalue* value, BasicType current_type, BasicType wide_type, TRAPS);
duke@435 77
duke@435 78 // Reflective array access. Returns type code. Throws ArrayIndexOutOfBoundsException.
duke@435 79 static BasicType array_get(jvalue* value, arrayOop a, int index, TRAPS);
duke@435 80 static void array_set(jvalue* value, arrayOop a, int index, BasicType value_type, TRAPS);
duke@435 81 // Returns mirror on array element type (NULL for basic type arrays and non-arrays).
duke@435 82 static oop array_component_type(oop mirror, TRAPS);
duke@435 83
duke@435 84 // Object creation
duke@435 85 static arrayOop reflect_new_array(oop element_mirror, jint length, TRAPS);
duke@435 86 static arrayOop reflect_new_multi_array(oop element_mirror, typeArrayOop dimensions, TRAPS);
duke@435 87
duke@435 88 // Verification
coleenp@4037 89 static bool verify_class_access(Klass* current_class, Klass* new_class, bool classloader_only);
duke@435 90
coleenp@4037 91 static bool verify_field_access(Klass* current_class,
coleenp@4037 92 Klass* resolved_class,
coleenp@4037 93 Klass* field_class,
duke@435 94 AccessFlags access,
duke@435 95 bool classloader_only,
duke@435 96 bool protected_restriction = false);
coleenp@4037 97 static bool is_same_class_package(Klass* class1, Klass* class2);
coleenp@4037 98 static bool is_same_package_member(Klass* class1, Klass* class2, TRAPS);
duke@435 99
duke@435 100 static bool can_relax_access_check_for(
coleenp@4037 101 Klass* accessor, Klass* accesee, bool classloader_only);
duke@435 102
duke@435 103 // inner class reflection
jrose@1100 104 // raise an ICCE unless the required relationship can be proven to hold
jrose@1100 105 // If inner_is_member, require the inner to be a member of the outer.
jrose@1100 106 // If !inner_is_member, require the inner to be anonymous (a non-member).
jrose@1100 107 // Caller is responsible for figuring out in advance which case must be true.
jrose@1100 108 static void check_for_inner_class(instanceKlassHandle outer, instanceKlassHandle inner,
jrose@1100 109 bool inner_is_member, TRAPS);
duke@435 110
duke@435 111 //
duke@435 112 // Support for reflection based on dynamic bytecode generation (JDK 1.4)
duke@435 113 //
duke@435 114
duke@435 115 // Create a java.lang.reflect.Method object based on a method
duke@435 116 static oop new_method(methodHandle method, bool intern_name, bool for_constant_pool_access, TRAPS);
duke@435 117 // Create a java.lang.reflect.Constructor object based on a method
duke@435 118 static oop new_constructor(methodHandle method, TRAPS);
duke@435 119 // Create a java.lang.reflect.Field object based on a field descriptor
duke@435 120 static oop new_field(fieldDescriptor* fd, bool intern_name, TRAPS);
coleenp@4398 121 // Create a java.lang.reflect.Parameter object based on a
coleenp@4398 122 // MethodParameterElement
coleenp@4398 123 static oop new_parameter(Handle method, int index, Symbol* sym,
coleenp@4398 124 int flags, TRAPS);
duke@435 125
duke@435 126 private:
duke@435 127 // method resolution for invoke
duke@435 128 static methodHandle resolve_interface_call(instanceKlassHandle klass, methodHandle method, KlassHandle recv_klass, Handle receiver, TRAPS);
duke@435 129 // Method call (shared by invoke_method and invoke_constructor)
duke@435 130 static oop invoke(instanceKlassHandle klass, methodHandle method, Handle receiver, bool override, objArrayHandle ptypes, BasicType rtype, objArrayHandle args, bool is_method_invoke, TRAPS);
duke@435 131
duke@435 132 // Narrowing of basic types. Used to create correct jvalues for
duke@435 133 // boolean, byte, char and short return return values from interpreter
duke@435 134 // which are returned as ints. Throws IllegalArgumentException.
duke@435 135 static void narrow(jvalue* value, BasicType narrow_type, TRAPS);
duke@435 136
duke@435 137 // Conversion
duke@435 138 static BasicType basic_type_mirror_to_basic_type(oop basic_type_mirror, TRAPS);
duke@435 139
duke@435 140 public:
duke@435 141 // Method invokation through java.lang.reflect.Method
duke@435 142 static oop invoke_method(oop method_mirror, Handle receiver, objArrayHandle args, TRAPS);
duke@435 143 // Method invokation through java.lang.reflect.Constructor
duke@435 144 static oop invoke_constructor(oop method_mirror, objArrayHandle args, TRAPS);
duke@435 145
duke@435 146 };
stefank@2314 147
stefank@2314 148 #endif // SHARE_VM_RUNTIME_REFLECTION_HPP

mercurial