1 /* 2 * Copyright (c) 1999, 2018, 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_VM_CI_CIOBJECT_HPP 26 #define SHARE_VM_CI_CIOBJECT_HPP 27 28 #include "ci/ciBaseObject.hpp" 29 #include "ci/ciClassList.hpp" 30 #include "memory/allocation.hpp" 31 #include "runtime/handles.hpp" 32 #include "runtime/jniHandles.hpp" 33 34 // ciObject 35 // 36 // This class represents an oop in the HotSpot virtual machine. 37 // Its subclasses are structured in a hierarchy which mirrors 38 // an aggregate of the VM's oop and klass hierarchies (see 39 // oopHierarchy.hpp). Each instance of ciObject holds a handle 40 // to a corresponding oop on the VM side and provides routines 41 // for accessing the information in its oop. By using the ciObject 42 // hierarchy for accessing oops in the VM, the compiler ensures 43 // that it is safe with respect to garbage collection; that is, 44 // GC and compilation can proceed independently without 45 // interference. 46 // 47 // Within the VM, the oop and klass hierarchies are separate. 48 // The compiler interface does not preserve this separation -- 49 // the distinction between `Klass*' and `Klass' are not 50 // reflected in the interface and instead the Klass hierarchy 51 // is directly modeled as the subclasses of ciKlass. 52 class ciObject : public ciBaseObject { 53 CI_PACKAGE_ACCESS 54 friend class ciEnv; 55 56 private: 57 // A JNI handle referring to an oop in the VM. This 58 // handle may, in a small set of cases, correctly be NULL. 59 jobject _handle; 60 ciKlass* _klass; 61 62 protected: 63 ciObject(); 64 ciObject(oop o); 65 ciObject(Handle h); 66 ciObject(ciKlass* klass); 67 68 jobject handle() const { return _handle; } 69 // Get the VM oop that this object holds. 70 oop get_oop() const; 71 72 void init_flags_from(oop x); 73 74 // Virtual behavior of the print() method. 75 virtual void print_impl(outputStream* st) {} 76 77 virtual const char* type_string() { return "ciObject"; } 78 79 public: 80 // The klass of this ciObject. 81 ciKlass* klass(); 82 83 // Are two ciObjects equal? 84 bool equals(ciObject* obj); 85 86 // A hash value for the convenience of compilers. 87 int hash(); 88 89 // Tells if this oop has an encoding as a constant. 90 // True if is_perm is true. 91 // Also true if ScavengeRootsInCode is non-zero. 92 // If it does not have an encoding, the compiler is responsible for 93 // making other arrangements for dealing with the oop. 94 // See ciEnv::make_array 95 bool can_be_constant(); 96 97 // Tells if this oop should be made a constant. 98 // True if is_perm is true or ScavengeRootsInCode > 1. 99 bool should_be_constant(); 100 101 // Might this object possibly move during a scavenge operation? 102 // If the answer is true and ScavengeRootsInCode==0, the oop cannot be embedded in code. 103 bool is_scavengable() { return (_ident & SCAVENGABLE_FLAG) != 0; } 104 105 // The address which the compiler should embed into the 106 // generated code to represent this oop. This address 107 // is not the true address of the oop -- it will get patched 108 // during nmethod creation. 109 // 110 // Usage note: no address arithmetic allowed. Oop must 111 // be registered with the oopRecorder. 112 jobject constant_encoding(); 113 114 virtual bool is_object() const { return true; } 115 116 // What kind of ciObject is this? 117 virtual bool is_null_object() const { return false; } 118 virtual bool is_call_site() const { return false; } 119 virtual bool is_cpcache() const { return false; } 120 virtual bool is_instance() { return false; } 121 virtual bool is_member_name() const { return false; } 122 virtual bool is_method_handle() const { return false; } 123 virtual bool is_method_type() const { return false; } 124 virtual bool is_array() { return false; } 125 virtual bool is_obj_array() { return false; } 126 virtual bool is_type_array() { return false; } 127 128 // Is this a type or value which has no associated class? 129 // It is true of primitive types and null objects. 130 virtual bool is_classless() const { return false; } 131 virtual void dump_replay_data(outputStream* st) { /* do nothing */ } 132 133 // Note: some ciObjects refer to oops which have yet to be created. 134 // We refer to these as "unloaded". Specifically, there are 135 // unloaded instances of java.lang.Class, 136 // java.lang.invoke.MethodHandle, and java.lang.invoke.MethodType. 137 // By convention the ciNullObject is considered loaded, and 138 // primitive types are considered loaded. 139 bool is_loaded() const { 140 return handle() != NULL || is_classless(); 141 } 142 143 // Subclass casting with assertions. 144 ciNullObject* as_null_object() { 145 assert(is_null_object(), "bad cast"); 146 return (ciNullObject*)this; 147 } 148 ciCallSite* as_call_site() { 149 assert(is_call_site(), "bad cast"); 150 return (ciCallSite*)this; 151 } 152 ciInstance* as_instance() { 153 assert(is_instance(), "bad cast"); 154 return (ciInstance*)this; 155 } 156 ciMemberName* as_member_name() { 157 assert(is_member_name(), "bad cast"); 158 return (ciMemberName*)this; 159 } 160 ciMethodHandle* as_method_handle() { 161 assert(is_method_handle(), "bad cast"); 162 return (ciMethodHandle*)this; 163 } 164 ciMethodType* as_method_type() { 165 assert(is_method_type(), "bad cast"); 166 return (ciMethodType*)this; 167 } 168 ciArray* as_array() { 169 assert(is_array(), "bad cast"); 170 return (ciArray*)this; 171 } 172 ciObjArray* as_obj_array() { 173 assert(is_obj_array(), "bad cast"); 174 return (ciObjArray*)this; 175 } 176 ciTypeArray* as_type_array() { 177 assert(is_type_array(), "bad cast"); 178 return (ciTypeArray*)this; 179 } 180 181 // Print debugging output about this ciObject. 182 void print(outputStream* st); 183 void print() { print(tty); } // GDB cannot handle default arguments 184 185 // Print debugging output about the oop this ciObject represents. 186 void print_oop(outputStream* st = tty); 187 }; 188 189 #endif // SHARE_VM_CI_CIOBJECT_HPP