1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/ci/ciObject.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,260 @@ 1.4 +/* 1.5 + * Copyright 1999-2006 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +// ciObject 1.29 +// 1.30 +// This class represents an oop in the HotSpot virtual machine. 1.31 +// Its subclasses are structured in a hierarchy which mirrors 1.32 +// an aggregate of the VM's oop and klass hierarchies (see 1.33 +// oopHierarchy.hpp). Each instance of ciObject holds a handle 1.34 +// to a corresponding oop on the VM side and provides routines 1.35 +// for accessing the information in its oop. By using the ciObject 1.36 +// hierarchy for accessing oops in the VM, the compiler ensures 1.37 +// that it is safe with respect to garbage collection; that is, 1.38 +// GC and compilation can proceed independently without 1.39 +// interference. 1.40 +// 1.41 +// Within the VM, the oop and klass hierarchies are separate. 1.42 +// The compiler interface does not preserve this separation -- 1.43 +// the distinction between `klassOop' and `Klass' are not 1.44 +// reflected in the interface and instead the Klass hierarchy 1.45 +// is directly modeled as the subclasses of ciKlass. 1.46 +class ciObject : public ResourceObj { 1.47 + CI_PACKAGE_ACCESS 1.48 + friend class ciEnv; 1.49 + 1.50 +private: 1.51 + // A JNI handle referring to an oop in the VM. This 1.52 + // handle may, in a small set of cases, correctly be NULL. 1.53 + jobject _handle; 1.54 + ciKlass* _klass; 1.55 + uint _ident; 1.56 + 1.57 + enum { FLAG_BITS = 1}; 1.58 + enum { 1.59 + PERM_FLAG = 1 1.60 + }; 1.61 +protected: 1.62 + ciObject(); 1.63 + ciObject(oop o); 1.64 + ciObject(Handle h); 1.65 + ciObject(ciKlass* klass); 1.66 + 1.67 + jobject handle() const { return _handle; } 1.68 + // Get the VM oop that this object holds. 1.69 + oop get_oop() const { 1.70 + assert(_handle != NULL, "null oop"); 1.71 + return JNIHandles::resolve_non_null(_handle); 1.72 + } 1.73 + 1.74 + void set_perm() { 1.75 + _ident |= PERM_FLAG; 1.76 + } 1.77 + 1.78 + // Virtual behavior of the print() method. 1.79 + virtual void print_impl(outputStream* st) {} 1.80 + 1.81 + virtual const char* type_string() { return "ciObject"; } 1.82 + 1.83 + void set_ident(uint id); 1.84 +public: 1.85 + // The klass of this ciObject. 1.86 + ciKlass* klass(); 1.87 + 1.88 + // A number unique to this object. 1.89 + uint ident(); 1.90 + 1.91 + // Are two ciObjects equal? 1.92 + bool equals(ciObject* obj); 1.93 + 1.94 + // A hash value for the convenience of compilers. 1.95 + int hash(); 1.96 + 1.97 + // Tells if this oop has an encoding. (I.e., is it null or perm?) 1.98 + // If it does not have an encoding, the compiler is responsible for 1.99 + // making other arrangements for dealing with the oop. 1.100 + // See ciEnv::make_perm_array 1.101 + bool has_encoding(); 1.102 + 1.103 + // Is this object guaranteed to be in the permanent part of the heap? 1.104 + // If so, CollectedHeap::can_elide_permanent_oop_store_barriers is relevant. 1.105 + // If the answer is false, no guarantees are made. 1.106 + bool is_perm() { return (_ident & PERM_FLAG) != 0; } 1.107 + 1.108 + // The address which the compiler should embed into the 1.109 + // generated code to represent this oop. This address 1.110 + // is not the true address of the oop -- it will get patched 1.111 + // during nmethod creation. 1.112 + // 1.113 + // Usage note: no address arithmetic allowed. Oop must 1.114 + // be registered with the oopRecorder. 1.115 + jobject encoding(); 1.116 + 1.117 + // What kind of ciObject is this? 1.118 + virtual bool is_null_object() const { return false; } 1.119 + virtual bool is_instance() { return false; } 1.120 + virtual bool is_method() { return false; } 1.121 + virtual bool is_method_data() { return false; } 1.122 + virtual bool is_array() { return false; } 1.123 + virtual bool is_obj_array() { return false; } 1.124 + virtual bool is_type_array() { return false; } 1.125 + virtual bool is_symbol() { return false; } 1.126 + virtual bool is_type() { return false; } 1.127 + virtual bool is_return_address() { return false; } 1.128 + virtual bool is_klass() { return false; } 1.129 + virtual bool is_instance_klass() { return false; } 1.130 + virtual bool is_method_klass() { return false; } 1.131 + virtual bool is_array_klass() { return false; } 1.132 + virtual bool is_obj_array_klass() { return false; } 1.133 + virtual bool is_type_array_klass() { return false; } 1.134 + virtual bool is_symbol_klass() { return false; } 1.135 + virtual bool is_klass_klass() { return false; } 1.136 + virtual bool is_instance_klass_klass() { return false; } 1.137 + virtual bool is_array_klass_klass() { return false; } 1.138 + virtual bool is_obj_array_klass_klass() { return false; } 1.139 + virtual bool is_type_array_klass_klass() { return false; } 1.140 + 1.141 + // Is this a type or value which has no associated class? 1.142 + // It is true of primitive types and null objects. 1.143 + virtual bool is_classless() const { return false; } 1.144 + 1.145 + // Is this ciObject a Java Language Object? That is, 1.146 + // is the ciObject an instance or an array 1.147 + virtual bool is_java_object() { return false; } 1.148 + 1.149 + // Does this ciObject represent a Java Language class? 1.150 + // That is, is the ciObject an instanceKlass or arrayKlass? 1.151 + virtual bool is_java_klass() { return false; } 1.152 + 1.153 + // Is this ciObject the ciInstanceKlass representing 1.154 + // java.lang.Object()? 1.155 + virtual bool is_java_lang_Object() { return false; } 1.156 + 1.157 + // Does this ciObject refer to a real oop in the VM? 1.158 + // 1.159 + // Note: some ciObjects refer to oops which have yet to be 1.160 + // created. We refer to these as "unloaded". Specifically, 1.161 + // there are unloaded ciMethods, ciObjArrayKlasses, and 1.162 + // ciInstanceKlasses. By convention the ciNullObject is 1.163 + // considered loaded, and primitive types are considered loaded. 1.164 + bool is_loaded() const { 1.165 + return handle() != NULL || is_classless(); 1.166 + } 1.167 + 1.168 + // Subclass casting with assertions. 1.169 + ciNullObject* as_null_object() { 1.170 + assert(is_null_object(), "bad cast"); 1.171 + return (ciNullObject*)this; 1.172 + } 1.173 + ciInstance* as_instance() { 1.174 + assert(is_instance(), "bad cast"); 1.175 + return (ciInstance*)this; 1.176 + } 1.177 + ciMethod* as_method() { 1.178 + assert(is_method(), "bad cast"); 1.179 + return (ciMethod*)this; 1.180 + } 1.181 + ciMethodData* as_method_data() { 1.182 + assert(is_method_data(), "bad cast"); 1.183 + return (ciMethodData*)this; 1.184 + } 1.185 + ciArray* as_array() { 1.186 + assert(is_array(), "bad cast"); 1.187 + return (ciArray*)this; 1.188 + } 1.189 + ciObjArray* as_obj_array() { 1.190 + assert(is_obj_array(), "bad cast"); 1.191 + return (ciObjArray*)this; 1.192 + } 1.193 + ciTypeArray* as_type_array() { 1.194 + assert(is_type_array(), "bad cast"); 1.195 + return (ciTypeArray*)this; 1.196 + } 1.197 + ciSymbol* as_symbol() { 1.198 + assert(is_symbol(), "bad cast"); 1.199 + return (ciSymbol*)this; 1.200 + } 1.201 + ciType* as_type() { 1.202 + assert(is_type(), "bad cast"); 1.203 + return (ciType*)this; 1.204 + } 1.205 + ciReturnAddress* as_return_address() { 1.206 + assert(is_return_address(), "bad cast"); 1.207 + return (ciReturnAddress*)this; 1.208 + } 1.209 + ciKlass* as_klass() { 1.210 + assert(is_klass(), "bad cast"); 1.211 + return (ciKlass*)this; 1.212 + } 1.213 + ciInstanceKlass* as_instance_klass() { 1.214 + assert(is_instance_klass(), "bad cast"); 1.215 + return (ciInstanceKlass*)this; 1.216 + } 1.217 + ciMethodKlass* as_method_klass() { 1.218 + assert(is_method_klass(), "bad cast"); 1.219 + return (ciMethodKlass*)this; 1.220 + } 1.221 + ciArrayKlass* as_array_klass() { 1.222 + assert(is_array_klass(), "bad cast"); 1.223 + return (ciArrayKlass*)this; 1.224 + } 1.225 + ciObjArrayKlass* as_obj_array_klass() { 1.226 + assert(is_obj_array_klass(), "bad cast"); 1.227 + return (ciObjArrayKlass*)this; 1.228 + } 1.229 + ciTypeArrayKlass* as_type_array_klass() { 1.230 + assert(is_type_array_klass(), "bad cast"); 1.231 + return (ciTypeArrayKlass*)this; 1.232 + } 1.233 + ciSymbolKlass* as_symbol_klass() { 1.234 + assert(is_symbol_klass(), "bad cast"); 1.235 + return (ciSymbolKlass*)this; 1.236 + } 1.237 + ciKlassKlass* as_klass_klass() { 1.238 + assert(is_klass_klass(), "bad cast"); 1.239 + return (ciKlassKlass*)this; 1.240 + } 1.241 + ciInstanceKlassKlass* as_instance_klass_klass() { 1.242 + assert(is_instance_klass_klass(), "bad cast"); 1.243 + return (ciInstanceKlassKlass*)this; 1.244 + } 1.245 + ciArrayKlassKlass* as_array_klass_klass() { 1.246 + assert(is_array_klass_klass(), "bad cast"); 1.247 + return (ciArrayKlassKlass*)this; 1.248 + } 1.249 + ciObjArrayKlassKlass* as_obj_array_klass_klass() { 1.250 + assert(is_obj_array_klass_klass(), "bad cast"); 1.251 + return (ciObjArrayKlassKlass*)this; 1.252 + } 1.253 + ciTypeArrayKlassKlass* as_type_array_klass_klass() { 1.254 + assert(is_type_array_klass_klass(), "bad cast"); 1.255 + return (ciTypeArrayKlassKlass*)this; 1.256 + } 1.257 + 1.258 + // Print debugging output about this ciObject. 1.259 + void print(outputStream* st = tty); 1.260 + 1.261 + // Print debugging output about the oop this ciObject represents. 1.262 + void print_oop(outputStream* st = tty); 1.263 +};