hotspot/src/share/vm/runtime/reflection.hpp
author coleenp
Fri, 23 Oct 2015 16:48:38 -0400
changeset 33593 60764a78fa5c
parent 25057 f38210f84f8c
child 34666 1c7168ea0034
permissions -rw-r--r--
8140274: methodHandles and constantPoolHandles should be passed as const references Summary: modified code to use const reference parameters Reviewed-by: sspitsyn, twisti
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 25057
diff changeset
     2
 * Copyright (c) 1997, 2015, 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 "utilities/accessFlags.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "utilities/growableArray.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// Class Reflection contains utility methods needed for implementing the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// reflection api.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// Used by functions in the JVM interface.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// NOTE that in JDK 1.4 most of reflection is now implemented in Java
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// using dynamic bytecode generation. The Array class has not yet been
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// rewritten using bytecodes; if it were, most of the rest of this
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// class could go away, as well as a few more entry points in jvm.cpp.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
class FieldStream;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
class Reflection: public AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  // Conversion
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10504
diff changeset
    48
  static Klass* basic_type_mirror_to_arrayklass(oop basic_type_mirror, TRAPS);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10504
diff changeset
    49
  static oop      basic_type_arrayklass_to_mirror(Klass* basic_type_arrayklass, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 25057
diff changeset
    51
  static objArrayHandle get_parameter_types(const methodHandle& method, int parameter_count, oop* return_type, TRAPS);
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 25057
diff changeset
    52
  static objArrayHandle get_exception_types(const methodHandle& method, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // Creating new java.lang.reflect.xxx wrappers
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    54
  static Handle new_type(Symbol* signature, KlassHandle k, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  // Constants defined by java reflection api classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  enum SomeConstants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    PUBLIC            = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    DECLARED          = 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    MEMBER_PUBLIC     = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    MEMBER_DECLARED   = 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    MAX_DIM           = 255
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // Boxing. Returns boxed value of appropriate type. Throws IllegalArgumentException.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  static oop box(jvalue* v, BasicType type, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  // Unboxing. Returns type code and sets value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  static BasicType unbox_for_primitive(oop boxed_value, jvalue* value, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  static BasicType unbox_for_regular_object(oop boxed_value, jvalue* value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // Widening of basic types. Throws IllegalArgumentException.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  static void widen(jvalue* value, BasicType current_type, BasicType wide_type, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  // Reflective array access. Returns type code. Throws ArrayIndexOutOfBoundsException.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  static BasicType array_get(jvalue* value, arrayOop a, int index, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  static void      array_set(jvalue* value, arrayOop a, int index, BasicType value_type, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  // Returns mirror on array element type (NULL for basic type arrays and non-arrays).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  static oop       array_component_type(oop mirror, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  // Object creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  static arrayOop reflect_new_array(oop element_mirror, jint length, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  static arrayOop reflect_new_multi_array(oop element_mirror, typeArrayOop dimensions, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  // Verification
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10504
diff changeset
    86
  static bool     verify_class_access(Klass* current_class, Klass* new_class, bool classloader_only);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10504
diff changeset
    88
  static bool     verify_field_access(Klass* current_class,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10504
diff changeset
    89
                                      Klass* resolved_class,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10504
diff changeset
    90
                                      Klass* field_class,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
                                      AccessFlags access,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
                                      bool classloader_only,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
                                      bool protected_restriction = false);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10504
diff changeset
    94
  static bool     is_same_class_package(Klass* class1, Klass* class2);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10504
diff changeset
    95
  static bool     is_same_package_member(Klass* class1, Klass* class2, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  static bool can_relax_access_check_for(
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10504
diff changeset
    98
    Klass* accessor, Klass* accesee, bool classloader_only);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  // inner class reflection
2332
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   101
  // 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
   102
  // 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
   103
  // 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
   104
  // 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
   105
  static void check_for_inner_class(instanceKlassHandle outer, instanceKlassHandle inner,
5c7b6f4ce0a1 6814659: separable cleanups and subroutines for 6655638
jrose
parents: 1
diff changeset
   106
                                    bool inner_is_member, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  // Support for reflection based on dynamic bytecode generation (JDK 1.4)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  // Create a java.lang.reflect.Method object based on a method
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 25057
diff changeset
   113
  static oop new_method(const methodHandle& method, bool for_constant_pool_access, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // Create a java.lang.reflect.Constructor object based on a method
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 25057
diff changeset
   115
  static oop new_constructor(const methodHandle& method, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // Create a java.lang.reflect.Field object based on a field descriptor
24456
8c7933fa5a1f 8025580: Temporary flags: UseNewReflection and ReflectionWrapResolutionErrors
coleenp
parents: 22551
diff changeset
   117
  static oop new_field(fieldDescriptor* fd, TRAPS);
15102
0a86564e5f61 8004728: Add hotspot support for parameter reflection
coleenp
parents: 13728
diff changeset
   118
  // Create a java.lang.reflect.Parameter object based on a
0a86564e5f61 8004728: Add hotspot support for parameter reflection
coleenp
parents: 13728
diff changeset
   119
  // MethodParameterElement
0a86564e5f61 8004728: Add hotspot support for parameter reflection
coleenp
parents: 13728
diff changeset
   120
  static oop new_parameter(Handle method, int index, Symbol* sym,
0a86564e5f61 8004728: Add hotspot support for parameter reflection
coleenp
parents: 13728
diff changeset
   121
                           int flags, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  // method resolution for invoke
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 25057
diff changeset
   125
  static methodHandle resolve_interface_call(instanceKlassHandle klass, const methodHandle& method, KlassHandle recv_klass, Handle receiver, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  // Method call (shared by invoke_method and invoke_constructor)
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 25057
diff changeset
   127
  static oop  invoke(instanceKlassHandle klass,
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 25057
diff changeset
   128
                     const methodHandle& method,
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 25057
diff changeset
   129
                     Handle receiver,
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 25057
diff changeset
   130
                     bool override,
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 25057
diff changeset
   131
                     objArrayHandle ptypes,
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 25057
diff changeset
   132
                     BasicType rtype,
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 25057
diff changeset
   133
                     objArrayHandle args,
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 25057
diff changeset
   134
                     bool is_method_invoke, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  // Narrowing of basic types. Used to create correct jvalues for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  // boolean, byte, char and short return return values from interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  // which are returned as ints. Throws IllegalArgumentException.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  static void narrow(jvalue* value, BasicType narrow_type, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  // Conversion
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  static BasicType basic_type_mirror_to_basic_type(oop basic_type_mirror, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
public:
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 22234
diff changeset
   145
  // Method invocation through java.lang.reflect.Method
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  static oop      invoke_method(oop method_mirror, Handle receiver, objArrayHandle args, TRAPS);
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 22234
diff changeset
   147
  // Method invocation through java.lang.reflect.Constructor
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  static oop      invoke_constructor(oop method_mirror, objArrayHandle args, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   151
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   152
#endif // SHARE_VM_RUNTIME_REFLECTION_HPP