src/hotspot/share/jvmci/jvmciJavaClasses.cpp
changeset 50409 76bca6678913
parent 47216 71c04702a3d5
child 51467 12997ebbc0d8
equal deleted inserted replaced
50408:a5fc0fb1d31d 50409:76bca6678913
     1 /*
     1 /*
     2  * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    20  * or visit www.oracle.com if you need additional information or have any
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 #include "precompiled.hpp"
    24 #include "precompiled.hpp"
       
    25 #include "classfile/symbolTable.hpp"
    25 #include "jvmci/jvmciJavaClasses.hpp"
    26 #include "jvmci/jvmciJavaClasses.hpp"
    26 #include "runtime/jniHandles.hpp"
       
    27 #include "classfile/symbolTable.hpp"
       
    28 #include "memory/resourceArea.hpp"
    27 #include "memory/resourceArea.hpp"
       
    28 #include "oops/oop.inline.hpp"
       
    29 #include "runtime/jniHandles.inline.hpp"
       
    30 
       
    31 
       
    32 // This macro expands for non-inline functions, in class declarations.
       
    33 
       
    34 #define START_CLASS(name)                                                                                                                                \
       
    35     void name::check(oop obj, const char* field_name, int offset) {                                                                                          \
       
    36       assert(obj != NULL, "NULL field access of %s.%s", #name, field_name);                                                                                  \
       
    37       assert(obj->is_a(SystemDictionary::name##_klass()), "wrong class, " #name " expected, found %s", obj->klass()->external_name());                       \
       
    38       assert(offset != 0, "must be valid offset");                                                                                                           \
       
    39     }
       
    40 
       
    41 #define END_CLASS
       
    42 
       
    43 #define FIELD(klass, name, type, accessor, cast)                                                                                                                                \
       
    44     type klass::name(jobject obj)               { check(JNIHandles::resolve(obj), #name, _##name##_offset); return cast JNIHandles::resolve(obj)->accessor(_##name##_offset); }     \
       
    45     void klass::set_##name(jobject obj, type x) { check(JNIHandles::resolve(obj), #name, _##name##_offset); JNIHandles::resolve(obj)->accessor##_put(_##name##_offset, x); }
       
    46 
       
    47 #define EMPTY_CAST
       
    48 #define CHAR_FIELD(klass, name) FIELD(klass, name, jchar, char_field, EMPTY_CAST)
       
    49 #define INT_FIELD(klass, name) FIELD(klass, name, jint, int_field, EMPTY_CAST)
       
    50 #define BOOLEAN_FIELD(klass, name) FIELD(klass, name, jboolean, bool_field, EMPTY_CAST)
       
    51 #define LONG_FIELD(klass, name) FIELD(klass, name, jlong, long_field, EMPTY_CAST)
       
    52 #define FLOAT_FIELD(klass, name) FIELD(klass, name, jfloat, float_field, EMPTY_CAST)
       
    53 #define OOP_FIELD(klass, name, signature) FIELD(klass, name, oop, obj_field, EMPTY_CAST)
       
    54 #define OBJARRAYOOP_FIELD(klass, name, signature) FIELD(klass, name, objArrayOop, obj_field, (objArrayOop))
       
    55 #define TYPEARRAYOOP_FIELD(klass, name, signature) FIELD(klass, name, typeArrayOop, obj_field, (typeArrayOop))
       
    56 #define STATIC_OOP_FIELD(klassName, name, signature) STATIC_OOPISH_FIELD(klassName, name, oop, signature)
       
    57 #define STATIC_OBJARRAYOOP_FIELD(klassName, name, signature) STATIC_OOPISH_FIELD(klassName, name, objArrayOop, signature)
       
    58 #define STATIC_OOPISH_FIELD(klassName, name, type, signature)                                                  \
       
    59     type klassName::name() {                                                                                   \
       
    60       assert(klassName::klass() != NULL && klassName::klass()->is_linked(), "Class not yet linked: " #klassName); \
       
    61       InstanceKlass* ik = klassName::klass();                                                                  \
       
    62       oop base = ik->static_field_base_raw();                                                                  \
       
    63       oop result = HeapAccess<>::oop_load_at(base, _##name##_offset);                                          \
       
    64       return type(result);                                                                                     \
       
    65     }                                                                                                          \
       
    66     void klassName::set_##name(type x) {                                                                       \
       
    67       assert(klassName::klass() != NULL && klassName::klass()->is_linked(), "Class not yet linked: " #klassName); \
       
    68       assert(klassName::klass() != NULL, "Class not yet loaded: " #klassName);                                 \
       
    69       InstanceKlass* ik = klassName::klass();                                                                  \
       
    70       oop base = ik->static_field_base_raw();                                                                  \
       
    71       HeapAccess<>::oop_store_at(base, _##name##_offset, x);                                                   \
       
    72     }
       
    73 #define STATIC_PRIMITIVE_FIELD(klassName, name, jtypename)                                                     \
       
    74     jtypename klassName::name() {                                                                              \
       
    75       assert(klassName::klass() != NULL && klassName::klass()->is_linked(), "Class not yet linked: " #klassName); \
       
    76       InstanceKlass* ik = klassName::klass();                                                                  \
       
    77       oop base = ik->static_field_base_raw();                                                                  \
       
    78       return HeapAccess<>::load_at(base, _##name##_offset);                                                    \
       
    79     }                                                                                                          \
       
    80     void klassName::set_##name(jtypename x) {                                                                  \
       
    81       assert(klassName::klass() != NULL && klassName::klass()->is_linked(), "Class not yet linked: " #klassName); \
       
    82       InstanceKlass* ik = klassName::klass();                                                                  \
       
    83       oop base = ik->static_field_base_raw();                                                                  \
       
    84       HeapAccess<>::store_at(base, _##name##_offset, x);                                                       \
       
    85     }
       
    86 
       
    87 #define STATIC_INT_FIELD(klassName, name) STATIC_PRIMITIVE_FIELD(klassName, name, jint)
       
    88 #define STATIC_BOOLEAN_FIELD(klassName, name) STATIC_PRIMITIVE_FIELD(klassName, name, jboolean)
       
    89 
       
    90 COMPILER_CLASSES_DO(START_CLASS, END_CLASS, CHAR_FIELD, INT_FIELD, BOOLEAN_FIELD, LONG_FIELD, FLOAT_FIELD, OOP_FIELD, TYPEARRAYOOP_FIELD, OBJARRAYOOP_FIELD, STATIC_OOP_FIELD, STATIC_OBJARRAYOOP_FIELD, STATIC_INT_FIELD, STATIC_BOOLEAN_FIELD)
       
    91 #undef START_CLASS
       
    92 #undef END_CLASS
       
    93 #undef FIELD
       
    94 #undef CHAR_FIELD
       
    95 #undef INT_FIELD
       
    96 #undef BOOLEAN_FIELD
       
    97 #undef LONG_FIELD
       
    98 #undef FLOAT_FIELD
       
    99 #undef OOP_FIELD
       
   100 #undef TYPEARRAYOOP_FIELD
       
   101 #undef OBJARRAYOOP_FIELD
       
   102 #undef STATIC_OOPISH_FIELD
       
   103 #undef STATIC_OOP_FIELD
       
   104 #undef STATIC_OBJARRAYOOP_FIELD
       
   105 #undef STATIC_INT_FIELD
       
   106 #undef STATIC_BOOLEAN_FIELD
       
   107 #undef STATIC_PRIMITIVE_FIELD
       
   108 #undef EMPTY_CAST
    29 
   109 
    30 // This function is similar to javaClasses.cpp, it computes the field offset of a (static or instance) field.
   110 // This function is similar to javaClasses.cpp, it computes the field offset of a (static or instance) field.
    31 // It looks up the name and signature symbols without creating new ones, all the symbols of these classes need to be already loaded.
   111 // It looks up the name and signature symbols without creating new ones, all the symbols of these classes need to be already loaded.
    32 
   112 
    33 void compute_offset(int &dest_offset, Klass* klass, const char* name, const char* signature, bool static_field, TRAPS) {
   113 void compute_offset(int &dest_offset, Klass* klass, const char* name, const char* signature, bool static_field, TRAPS) {
    84 #define FIELD2(klass, name) int klass::_##name##_offset = 0;
   164 #define FIELD2(klass, name) int klass::_##name##_offset = 0;
    85 #define FIELD3(klass, name, sig) FIELD2(klass, name)
   165 #define FIELD3(klass, name, sig) FIELD2(klass, name)
    86 
   166 
    87 COMPILER_CLASSES_DO(EMPTY1, EMPTY0, FIELD2, FIELD2, FIELD2, FIELD2, FIELD2, FIELD3, FIELD3, FIELD3, FIELD3, FIELD3, FIELD2, FIELD2)
   167 COMPILER_CLASSES_DO(EMPTY1, EMPTY0, FIELD2, FIELD2, FIELD2, FIELD2, FIELD2, FIELD3, FIELD3, FIELD3, FIELD3, FIELD3, FIELD2, FIELD2)
    88 
   168 
    89 
       
    90 
       
    91 
       
    92