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 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_instance() { return false; } 119 virtual bool is_member_name() const { return false; } 120 virtual bool is_method_handle() const { return false; } 121 virtual bool is_method_type() const { return false; } 122 virtual bool is_array() { return false; } 123 virtual bool is_obj_array() { return false; } 124 virtual bool is_type_array() { return false; } 125 126 // Is this a type or value which has no associated class? 127 // It is true of primitive types and null objects. 128 virtual bool is_classless() const { return false; } 129 virtual void dump_replay_data(outputStream* st) { /* do nothing */ } 130 131 // Note: some ciObjects refer to oops which have yet to be created. 132 // We refer to these as "unloaded". Specifically, there are 133 // unloaded instances of java.lang.Class, 134 // java.lang.invoke.MethodHandle, and java.lang.invoke.MethodType. 135 // By convention the ciNullObject is considered loaded, and 136 // primitive types are considered loaded. 137 bool is_loaded() const { 138 return handle() != NULL || is_classless(); 139 } 140 141 // Subclass casting with assertions. 142 ciNullObject* as_null_object() { 143 assert(is_null_object(), "bad cast"); 144 return (ciNullObject*)this; 145 } 146 ciCallSite* as_call_site() { 147 assert(is_call_site(), "bad cast"); 148 return (ciCallSite*)this; 149 } 150 ciInstance* as_instance() { 151 assert(is_instance(), "bad cast"); 152 return (ciInstance*)this; 153 } 154 ciMemberName* as_member_name() { 155 assert(is_member_name(), "bad cast"); 156 return (ciMemberName*)this; 157 } 158 ciMethodHandle* as_method_handle() { 159 assert(is_method_handle(), "bad cast"); 160 return (ciMethodHandle*)this; 161 } 162 ciMethodType* as_method_type() { 163 assert(is_method_type(), "bad cast"); 164 return (ciMethodType*)this; 165 } 166 ciArray* as_array() { 167 assert(is_array(), "bad cast"); 168 return (ciArray*)this; 169 } 170 ciObjArray* as_obj_array() { 171 assert(is_obj_array(), "bad cast"); 172 return (ciObjArray*)this; 173 } 174 ciTypeArray* as_type_array() { 175 assert(is_type_array(), "bad cast"); 176 return (ciTypeArray*)this; 177 } 178 179 // Print debugging output about this ciObject. 180 void print(outputStream* st); 181 void print() { print(tty); } // GDB cannot handle default arguments 182 183 // Print debugging output about the oop this ciObject represents. 184 void print_oop(outputStream* st = tty); 185 }; 186 187 #endif // SHARE_CI_CIOBJECT_HPP