0N/A/*
2273N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_RUNTIME_REFLECTION_HPP
1879N/A#define SHARE_VM_RUNTIME_REFLECTION_HPP
1879N/A
1879N/A#include "oops/oop.hpp"
1879N/A#include "runtime/fieldDescriptor.hpp"
1879N/A#include "utilities/accessFlags.hpp"
1879N/A#include "utilities/growableArray.hpp"
1879N/A
0N/A// Class Reflection contains utility methods needed for implementing the
0N/A// reflection api.
0N/A//
0N/A// Used by functions in the JVM interface.
0N/A//
0N/A// NOTE that in JDK 1.4 most of reflection is now implemented in Java
0N/A// using dynamic bytecode generation. The Array class has not yet been
0N/A// rewritten using bytecodes; if it were, most of the rest of this
0N/A// class could go away, as well as a few more entry points in jvm.cpp.
0N/A
0N/Aclass FieldStream;
0N/A
0N/Aclass Reflection: public AllStatic {
0N/A private:
0N/A // Access checking
0N/A static bool reflect_check_access(klassOop field_class, AccessFlags acc, klassOop target_class, bool is_method_invoke, TRAPS);
0N/A
0N/A // Conversion
0N/A static klassOop basic_type_mirror_to_arrayklass(oop basic_type_mirror, TRAPS);
0N/A static oop basic_type_arrayklass_to_mirror(klassOop basic_type_arrayklass, TRAPS);
0N/A
0N/A static objArrayHandle get_parameter_types(methodHandle method, int parameter_count, oop* return_type, TRAPS);
0N/A static objArrayHandle get_exception_types(methodHandle method, TRAPS);
0N/A // Creating new java.lang.reflect.xxx wrappers
2062N/A static Handle new_type(Symbol* signature, KlassHandle k, TRAPS);
0N/A
0N/A public:
0N/A // Constants defined by java reflection api classes
0N/A enum SomeConstants {
0N/A PUBLIC = 0,
0N/A DECLARED = 1,
0N/A MEMBER_PUBLIC = 0,
0N/A MEMBER_DECLARED = 1,
0N/A MAX_DIM = 255
0N/A };
0N/A
0N/A // Boxing. Returns boxed value of appropriate type. Throws IllegalArgumentException.
0N/A static oop box(jvalue* v, BasicType type, TRAPS);
0N/A // Unboxing. Returns type code and sets value.
0N/A static BasicType unbox_for_primitive(oop boxed_value, jvalue* value, TRAPS);
0N/A static BasicType unbox_for_regular_object(oop boxed_value, jvalue* value);
0N/A
0N/A // Widening of basic types. Throws IllegalArgumentException.
0N/A static void widen(jvalue* value, BasicType current_type, BasicType wide_type, TRAPS);
0N/A
0N/A // Reflective array access. Returns type code. Throws ArrayIndexOutOfBoundsException.
0N/A static BasicType array_get(jvalue* value, arrayOop a, int index, TRAPS);
0N/A static void array_set(jvalue* value, arrayOop a, int index, BasicType value_type, TRAPS);
0N/A // Returns mirror on array element type (NULL for basic type arrays and non-arrays).
0N/A static oop array_component_type(oop mirror, TRAPS);
0N/A
0N/A // Object creation
0N/A static arrayOop reflect_new_array(oop element_mirror, jint length, TRAPS);
0N/A static arrayOop reflect_new_multi_array(oop element_mirror, typeArrayOop dimensions, TRAPS);
0N/A
0N/A // Verification
0N/A static bool verify_class_access(klassOop current_class, klassOop new_class, bool classloader_only);
0N/A
0N/A static bool verify_field_access(klassOop current_class,
0N/A klassOop resolved_class,
0N/A klassOop field_class,
0N/A AccessFlags access,
0N/A bool classloader_only,
0N/A bool protected_restriction = false);
0N/A static bool is_same_class_package(klassOop class1, klassOop class2);
665N/A static bool is_same_package_member(klassOop class1, klassOop class2, TRAPS);
0N/A
0N/A static bool can_relax_access_check_for(
0N/A klassOop accessor, klassOop accesee, bool classloader_only);
0N/A
0N/A // inner class reflection
665N/A // raise an ICCE unless the required relationship can be proven to hold
665N/A // If inner_is_member, require the inner to be a member of the outer.
665N/A // If !inner_is_member, require the inner to be anonymous (a non-member).
665N/A // Caller is responsible for figuring out in advance which case must be true.
665N/A static void check_for_inner_class(instanceKlassHandle outer, instanceKlassHandle inner,
665N/A bool inner_is_member, TRAPS);
0N/A
0N/A //
0N/A // Support for reflection based on dynamic bytecode generation (JDK 1.4)
0N/A //
0N/A
0N/A // Create a java.lang.reflect.Method object based on a method
0N/A static oop new_method(methodHandle method, bool intern_name, bool for_constant_pool_access, TRAPS);
0N/A // Create a java.lang.reflect.Constructor object based on a method
0N/A static oop new_constructor(methodHandle method, TRAPS);
0N/A // Create a java.lang.reflect.Field object based on a field descriptor
0N/A static oop new_field(fieldDescriptor* fd, bool intern_name, TRAPS);
0N/A
0N/Aprivate:
0N/A // method resolution for invoke
0N/A static methodHandle resolve_interface_call(instanceKlassHandle klass, methodHandle method, KlassHandle recv_klass, Handle receiver, TRAPS);
0N/A // Method call (shared by invoke_method and invoke_constructor)
0N/A static oop invoke(instanceKlassHandle klass, methodHandle method, Handle receiver, bool override, objArrayHandle ptypes, BasicType rtype, objArrayHandle args, bool is_method_invoke, TRAPS);
0N/A
0N/A // Narrowing of basic types. Used to create correct jvalues for
0N/A // boolean, byte, char and short return return values from interpreter
0N/A // which are returned as ints. Throws IllegalArgumentException.
0N/A static void narrow(jvalue* value, BasicType narrow_type, TRAPS);
0N/A
0N/A // Conversion
0N/A static BasicType basic_type_mirror_to_basic_type(oop basic_type_mirror, TRAPS);
0N/A
0N/Apublic:
0N/A // Method invokation through java.lang.reflect.Method
0N/A static oop invoke_method(oop method_mirror, Handle receiver, objArrayHandle args, TRAPS);
0N/A // Method invokation through java.lang.reflect.Constructor
0N/A static oop invoke_constructor(oop method_mirror, objArrayHandle args, TRAPS);
0N/A
0N/A};
1879N/A
1879N/A#endif // SHARE_VM_RUNTIME_REFLECTION_HPP