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 "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 67 jobject handle() const { return _handle; } 68 // Get the VM oop that this object holds. 69 oop get_oop() const; 70 71 void init_flags_from(oop x); 72 73 // Virtual behavior of the print() method. 74 virtual void print_impl(outputStream* st) {} 75 76 virtual const char* type_string() { return "ciObject"; } 77 78 public: 79 // The klass of this ciObject. 80 ciKlass* klass(); 81 82 // Are two ciObjects equal? 83 bool equals(ciObject* obj); 84 85 // A hash value for the convenience of compilers. 86 int hash(); 87 88 // Tells if this oop has an encoding as a constant. 89 // True if is_perm is true. 90 // Also true if ScavengeRootsInCode is non-zero. 91 // If it does not have an encoding, the compiler is responsible for 92 // making other arrangements for dealing with the oop. 93 // See ciEnv::make_array 94 bool can_be_constant(); 95 96 // Tells if this oop should be made a constant. 97 // True if is_perm is true or ScavengeRootsInCode > 1. 98 bool should_be_constant(); 99 100 // Might this object possibly move during a scavenge operation? 101 // If the answer is true and ScavengeRootsInCode==0, the oop cannot be embedded in code. 102 bool is_scavengable() { return (_ident & SCAVENGABLE_FLAG) != 0; } 103 104 // The address which the compiler should embed into the 105 // generated code to represent this oop. This address 106 // is not the true address of the oop -- it will get patched 107 // during nmethod creation. 108 // 109 // Usage note: no address arithmetic allowed. Oop must 110 // be registered with the oopRecorder. 111 jobject constant_encoding(); 112 113 virtual bool is_object() const { return true; } 114 115 // What kind of ciObject is this? 116 virtual bool is_null_object() const { return false; } 117 virtual bool is_call_site() const { return false; } 118 virtual bool is_cpcache() const { return false; } 119 virtual bool is_instance() { return false; } 120 virtual bool is_member_name() const { return false; } 121 virtual bool is_method_handle() const { return false; } 122 virtual bool is_method_type() const { return false; } 123 virtual bool is_array() { return false; } 124 virtual bool is_obj_array() { return false; } 125 virtual bool is_type_array() { return false; } 126 127 // Is this a type or value which has no associated class? 128 // It is true of primitive types and null objects. 129 virtual bool is_classless() const { return false; } 130 virtual void dump_replay_data(outputStream* st) { /* do nothing */ } 131 132 // Note: some ciObjects refer to oops which have yet to be created. 133 // We refer to these as "unloaded". Specifically, there are 134 // unloaded instances of java.lang.Class, 135 // java.lang.invoke.MethodHandle, and java.lang.invoke.MethodType. 136 // By convention the ciNullObject is considered loaded, and 137 // primitive types are considered loaded. 138 bool is_loaded() const { 139 return handle() != NULL || is_classless(); 140 } 141 142 // Subclass casting with assertions. 143 ciNullObject* as_null_object() { 144 assert(is_null_object(), "bad cast"); 145 return (ciNullObject*)this; 146 } 147 ciCallSite* as_call_site() { 148 assert(is_call_site(), "bad cast"); 149 return (ciCallSite*)this; 150 } 151 ciInstance* as_instance() { 152 assert(is_instance(), "bad cast"); 153 return (ciInstance*)this; 154 } 155 ciMemberName* as_member_name() { 156 assert(is_member_name(), "bad cast"); 157 return (ciMemberName*)this; 158 } 159 ciMethodHandle* as_method_handle() { 160 assert(is_method_handle(), "bad cast"); 161 return (ciMethodHandle*)this; 162 } 163 ciMethodType* as_method_type() { 164 assert(is_method_type(), "bad cast"); 165 return (ciMethodType*)this; 166 } 167 ciArray* as_array() { 168 assert(is_array(), "bad cast"); 169 return (ciArray*)this; 170 } 171 ciObjArray* as_obj_array() { 172 assert(is_obj_array(), "bad cast"); 173 return (ciObjArray*)this; 174 } 175 ciTypeArray* as_type_array() { 176 assert(is_type_array(), "bad cast"); 177 return (ciTypeArray*)this; 178 } 179 180 // Print debugging output about this ciObject. 181 void print(outputStream* st); 182 void print() { print(tty); } // GDB cannot handle default arguments 183 184 // Print debugging output about the oop this ciObject represents. 185 void print_oop(outputStream* st = tty); 186 }; 187 188 #endif // SHARE_VM_CI_CIOBJECT_HPP