hotspot/src/share/vm/runtime/reflection.hpp
author trims
Tue, 05 Apr 2011 14:12:31 -0700
changeset 8921 14bfe81f2a9d
parent 8076 96d498ec7ae1
child 10504 754cf4e432f4
permissions -rw-r--r--
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass Summary: Update the copyright to be 2010 on all changed files in OpenJDK Reviewed-by: ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
8921
14bfe81f2a9d 7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents: 8076
diff changeset
     2
 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2332
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2332
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2332
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#ifndef SHARE_VM_RUNTIME_REFLECTION_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_RUNTIME_REFLECTION_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "oops/oop.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "runtime/fieldDescriptor.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "runtime/reflectionCompat.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "utilities/accessFlags.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "utilities/growableArray.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// Class Reflection contains utility methods needed for implementing the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// reflection api.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// Used by functions in the JVM interface.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// NOTE that in JDK 1.4 most of reflection is now implemented in Java
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// using dynamic bytecode generation. The Array class has not yet been
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// rewritten using bytecodes; if it were, most of the rest of this
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// class could go away, as well as a few more entry points in jvm.cpp.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
class FieldStream;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
class Reflection: public AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  // Access checking
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  static bool reflect_check_access(klassOop field_class, AccessFlags acc, klassOop target_class, bool is_method_invoke, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  // Conversion
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  static klassOop basic_type_mirror_to_arrayklass(oop basic_type_mirror, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  static oop      basic_type_arrayklass_to_mirror(klassOop basic_type_arrayklass, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  static objArrayHandle get_parameter_types(methodHandle method, int parameter_count, oop* return_type, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  static objArrayHandle get_exception_types(methodHandle method, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  // Creating new java.lang.reflect.xxx wrappers
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    58
  static Handle new_type(Symbol* signature, KlassHandle k, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  // Constants defined by java reflection api classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  enum SomeConstants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    PUBLIC            = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    DECLARED          = 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    MEMBER_PUBLIC     = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    MEMBER_DECLARED   = 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    MAX_DIM           = 255
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // Boxing. Returns boxed value of appropriate type. Throws IllegalArgumentException.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  static oop box(jvalue* v, BasicType type, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // Unboxing. Returns type code and sets value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  static BasicType unbox_for_primitive(oop boxed_value, jvalue* value, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  static BasicType unbox_for_regular_object(oop boxed_value, jvalue* value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  // Widening of basic types. Throws IllegalArgumentException.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  static void widen(jvalue* value, BasicType current_type, BasicType wide_type, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // Reflective array access. Returns type code. Throws ArrayIndexOutOfBoundsException.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  static BasicType array_get(jvalue* value, arrayOop a, int index, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  static void      array_set(jvalue* value, arrayOop a, int index, BasicType value_type, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  // Returns mirror on array element type (NULL for basic type arrays and non-arrays).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  static oop       array_component_type(oop mirror, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  // Object creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  static arrayOop reflect_new_array(oop element_mirror, jint length, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  static arrayOop reflect_new_multi_array(oop element_mirror, typeArrayOop dimensions, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // Verification
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  static bool     verify_class_access(klassOop current_class, klassOop new_class, bool classloader_only);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  static bool     verify_field_access(klassOop current_class,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
                                      klassOop resolved_class,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
                                      klassOop field_class,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
                                      AccessFlags access,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
                                      bool classloader_only,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
                                      bool protected_restriction = false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  static bool     is_same_class_package(klassOop class1, klassOop class2);
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
    99
  static bool     is_same_package_member(klassOop class1, klassOop class2, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  static bool can_relax_access_check_for(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    klassOop accessor, klassOop accesee, bool classloader_only);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // inner class reflection
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   105
  // raise an ICCE unless the required relationship can be proven to hold
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   106
  // If inner_is_member, require the inner to be a member of the outer.
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   107
  // If !inner_is_member, require the inner to be anonymous (a non-member).
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   108
  // Caller is responsible for figuring out in advance which case must be true.
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   109
  static void check_for_inner_class(instanceKlassHandle outer, instanceKlassHandle inner,
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   110
                                    bool inner_is_member, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  // Support for reflection based on dynamic bytecode generation (JDK 1.4)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // Create a java.lang.reflect.Method object based on a method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  static oop new_method(methodHandle method, bool intern_name, bool for_constant_pool_access, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  // Create a java.lang.reflect.Constructor object based on a method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  static oop new_constructor(methodHandle method, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  // Create a java.lang.reflect.Field object based on a field descriptor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  static oop new_field(fieldDescriptor* fd, bool intern_name, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  //---------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // Support for old native code-based reflection (pre-JDK 1.4)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // NOTE: the method and constructor invocation code is still used
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // for startup time reasons; see reflectionCompat.hpp.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  //---------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
#ifdef SUPPORT_OLD_REFLECTION
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  // method resolution for invoke
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  static methodHandle resolve_interface_call(instanceKlassHandle klass, methodHandle method, KlassHandle recv_klass, Handle receiver, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  // Method call (shared by invoke_method and invoke_constructor)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  static oop  invoke(instanceKlassHandle klass, methodHandle method, Handle receiver, bool override, objArrayHandle ptypes, BasicType rtype, objArrayHandle args, bool is_method_invoke, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  // Narrowing of basic types. Used to create correct jvalues for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  // boolean, byte, char and short return return values from interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  // which are returned as ints. Throws IllegalArgumentException.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  static void narrow(jvalue* value, BasicType narrow_type, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  // Conversion
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  static BasicType basic_type_mirror_to_basic_type(oop basic_type_mirror, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  static bool match_parameter_types(methodHandle method, objArrayHandle types, int parameter_count, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // Creating new java.lang.reflect.xxx wrappers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  static oop new_field(FieldStream* st, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  // Field lookup and verification.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  static bool      resolve_field(Handle field_mirror, Handle& receiver, fieldDescriptor* fd, bool check_final, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  // Reflective field access. Returns type code. Throws IllegalArgumentException.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  static BasicType field_get(jvalue* value, fieldDescriptor* fd, Handle receiver);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  static void      field_set(jvalue* value, fieldDescriptor* fd, Handle receiver, BasicType value_type, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  // Reflective lookup of fields. Returns java.lang.reflect.Field instances.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   160
  static oop         reflect_field(oop mirror, Symbol* field_name, jint which, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  static objArrayOop reflect_fields(oop mirror, jint which, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  // Reflective lookup of methods. Returns java.lang.reflect.Method instances.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   164
  static oop         reflect_method(oop mirror, Symbol* method_name, objArrayHandle types, jint which, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  static objArrayOop reflect_methods(oop mirror, jint which, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  // Reflective lookup of constructors. Returns java.lang.reflect.Constructor instances.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  static oop         reflect_constructor(oop mirror, objArrayHandle types, jint which, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  static objArrayOop reflect_constructors(oop mirror, jint which, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  // Method invokation through java.lang.reflect.Method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  static oop      invoke_method(oop method_mirror, Handle receiver, objArrayHandle args, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  // Method invokation through java.lang.reflect.Constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  static oop      invoke_constructor(oop method_mirror, objArrayHandle args, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
#endif /* SUPPORT_OLD_REFLECTION */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   178
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   179
#endif // SHARE_VM_RUNTIME_REFLECTION_HPP