1 /* 2 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_CI_CIOBJECT_HPP 26 #define SHARE_CI_CIOBJECT_HPP 27 28 #include "ci/ciBaseObject.hpp" 29 #include "ci/ciClassList.hpp" 30 #include "runtime/handles.hpp" 31 #include "runtime/jniHandles.hpp" 32 33 // ciObject 34 // 35 // This class represents an oop in the HotSpot virtual machine. 36 // Its subclasses are structured in a hierarchy which mirrors 37 // an aggregate of the VM's oop and klass hierarchies (see 38 // oopHierarchy.hpp). Each instance of ciObject holds a handle 39 // to a corresponding oop on the VM side and provides routines 40 // for accessing the information in its oop. By using the ciObject 41 // hierarchy for accessing oops in the VM, the compiler ensures 42 // that it is safe with respect to garbage collection; that is, 43 // GC and compilation can proceed independently without 44 // interference. 45 // 46 // Within the VM, the oop and klass hierarchies are separate. 47 // The compiler interface does not preserve this separation -- 48 // the distinction between `Klass*' and `Klass' are not 49 // reflected in the interface and instead the Klass hierarchy 50 // is directly modeled as the subclasses of ciKlass. 51 class ciObject : public ciBaseObject { 52 CI_PACKAGE_ACCESS 53 friend class ciEnv; 54 55 private: 56 // A JNI handle referring to an oop in the VM. This 57 // handle may, in a small set of cases, correctly be NULL. 58 jobject _handle; 59 ciKlass* _klass; 60 61 protected: 62 ciObject(); 63 ciObject(oop o); 64 ciObject(Handle h); 65 ciObject(ciKlass* klass); 66 handle() const67 jobject handle() const { return _handle; } 68 // Get the VM oop that this object holds. 69 oop get_oop() const; 70 71 // Virtual behavior of the print() method. print_impl(outputStream * st)72 virtual void print_impl(outputStream* st) {} 73 type_string()74 virtual const char* type_string() { return "ciObject"; } 75 76 public: 77 // The klass of this ciObject. 78 ciKlass* klass(); 79 80 // Are two ciObjects equal? 81 bool equals(ciObject* obj); 82 83 // A hash value for the convenience of compilers. 84 int hash(); 85 86 // Tells if this oop should be made a constant. 87 bool should_be_constant(); 88 89 // The address which the compiler should embed into the 90 // generated code to represent this oop. This address 91 // is not the true address of the oop -- it will get patched 92 // during nmethod creation. 93 // 94 // Usage note: no address arithmetic allowed. Oop must 95 // be registered with the oopRecorder. 96 jobject constant_encoding(); 97 is_object() const98 virtual bool is_object() const { return true; } 99 100 // What kind of ciObject is this? is_null_object() const101 virtual bool is_null_object() const { return false; } is_call_site() const102 virtual bool is_call_site() const { return false; } is_instance()103 virtual bool is_instance() { return false; } is_member_name() const104 virtual bool is_member_name() const { return false; } is_method_handle() const105 virtual bool is_method_handle() const { return false; } is_method_type() const106 virtual bool is_method_type() const { return false; } is_array()107 virtual bool is_array() { return false; } is_obj_array()108 virtual bool is_obj_array() { return false; } is_type_array()109 virtual bool is_type_array() { return false; } 110 111 // Is this a type or value which has no associated class? 112 // It is true of primitive types and null objects. is_classless() const113 virtual bool is_classless() const { return false; } dump_replay_data(outputStream * st)114 virtual void dump_replay_data(outputStream* st) { /* do nothing */ } 115 116 // Note: some ciObjects refer to oops which have yet to be created. 117 // We refer to these as "unloaded". Specifically, there are 118 // unloaded instances of java.lang.Class, 119 // java.lang.invoke.MethodHandle, and java.lang.invoke.MethodType. 120 // By convention the ciNullObject is considered loaded, and 121 // primitive types are considered loaded. is_loaded() const122 bool is_loaded() const { 123 return handle() != NULL || is_classless(); 124 } 125 126 // Subclass casting with assertions. as_null_object()127 ciNullObject* as_null_object() { 128 assert(is_null_object(), "bad cast"); 129 return (ciNullObject*)this; 130 } as_call_site()131 ciCallSite* as_call_site() { 132 assert(is_call_site(), "bad cast"); 133 return (ciCallSite*)this; 134 } as_instance()135 ciInstance* as_instance() { 136 assert(is_instance(), "bad cast"); 137 return (ciInstance*)this; 138 } as_member_name()139 ciMemberName* as_member_name() { 140 assert(is_member_name(), "bad cast"); 141 return (ciMemberName*)this; 142 } as_method_handle()143 ciMethodHandle* as_method_handle() { 144 assert(is_method_handle(), "bad cast"); 145 return (ciMethodHandle*)this; 146 } as_method_type()147 ciMethodType* as_method_type() { 148 assert(is_method_type(), "bad cast"); 149 return (ciMethodType*)this; 150 } as_array()151 ciArray* as_array() { 152 assert(is_array(), "bad cast"); 153 return (ciArray*)this; 154 } as_obj_array()155 ciObjArray* as_obj_array() { 156 assert(is_obj_array(), "bad cast"); 157 return (ciObjArray*)this; 158 } as_type_array()159 ciTypeArray* as_type_array() { 160 assert(is_type_array(), "bad cast"); 161 return (ciTypeArray*)this; 162 } 163 164 // Print debugging output about this ciObject. 165 void print(outputStream* st); print()166 void print() { print(tty); } // GDB cannot handle default arguments 167 168 // Print debugging output about the oop this ciObject represents. 169 void print_oop(outputStream* st = tty); 170 }; 171 172 #endif // SHARE_CI_CIOBJECT_HPP 173