src/share/vm/ci/ciObject.hpp

Wed, 12 Oct 2011 21:00:13 -0700

author
twisti
date
Wed, 12 Oct 2011 21:00:13 -0700
changeset 3197
5eb9169b1a14
parent 2933
28a9fe9534ea
child 3969
1d7922586cf6
permissions
-rw-r--r--

7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
Reviewed-by: jrose, never

duke@435 1 /*
trims@2708 2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_CI_CIOBJECT_HPP
stefank@2314 26 #define SHARE_VM_CI_CIOBJECT_HPP
stefank@2314 27
stefank@2314 28 #include "ci/ciClassList.hpp"
stefank@2314 29 #include "memory/allocation.hpp"
stefank@2314 30 #include "runtime/handles.hpp"
stefank@2314 31 #include "runtime/jniHandles.hpp"
stefank@2314 32
duke@435 33 // ciObject
duke@435 34 //
duke@435 35 // This class represents an oop in the HotSpot virtual machine.
duke@435 36 // Its subclasses are structured in a hierarchy which mirrors
duke@435 37 // an aggregate of the VM's oop and klass hierarchies (see
duke@435 38 // oopHierarchy.hpp). Each instance of ciObject holds a handle
duke@435 39 // to a corresponding oop on the VM side and provides routines
duke@435 40 // for accessing the information in its oop. By using the ciObject
duke@435 41 // hierarchy for accessing oops in the VM, the compiler ensures
duke@435 42 // that it is safe with respect to garbage collection; that is,
duke@435 43 // GC and compilation can proceed independently without
duke@435 44 // interference.
duke@435 45 //
duke@435 46 // Within the VM, the oop and klass hierarchies are separate.
duke@435 47 // The compiler interface does not preserve this separation --
duke@435 48 // the distinction between `klassOop' and `Klass' are not
duke@435 49 // reflected in the interface and instead the Klass hierarchy
duke@435 50 // is directly modeled as the subclasses of ciKlass.
duke@435 51 class ciObject : public ResourceObj {
duke@435 52 CI_PACKAGE_ACCESS
duke@435 53 friend class ciEnv;
duke@435 54
duke@435 55 private:
duke@435 56 // A JNI handle referring to an oop in the VM. This
duke@435 57 // handle may, in a small set of cases, correctly be NULL.
duke@435 58 jobject _handle;
duke@435 59 ciKlass* _klass;
duke@435 60 uint _ident;
duke@435 61
jrose@1424 62 enum { FLAG_BITS = 2 };
duke@435 63 enum {
jrose@1424 64 PERM_FLAG = 1,
jrose@1424 65 SCAVENGABLE_FLAG = 2
duke@435 66 };
duke@435 67 protected:
duke@435 68 ciObject();
duke@435 69 ciObject(oop o);
duke@435 70 ciObject(Handle h);
duke@435 71 ciObject(ciKlass* klass);
duke@435 72
duke@435 73 jobject handle() const { return _handle; }
duke@435 74 // Get the VM oop that this object holds.
duke@435 75 oop get_oop() const {
duke@435 76 assert(_handle != NULL, "null oop");
duke@435 77 return JNIHandles::resolve_non_null(_handle);
duke@435 78 }
duke@435 79
jrose@1424 80 void init_flags_from(oop x) {
jrose@1424 81 int flags = 0;
jrose@1424 82 if (x != NULL) {
jrose@1424 83 if (x->is_perm())
jrose@1424 84 flags |= PERM_FLAG;
jrose@1424 85 if (x->is_scavengable())
jrose@1424 86 flags |= SCAVENGABLE_FLAG;
jrose@1424 87 }
jrose@1424 88 _ident |= flags;
duke@435 89 }
duke@435 90
duke@435 91 // Virtual behavior of the print() method.
duke@435 92 virtual void print_impl(outputStream* st) {}
duke@435 93
duke@435 94 virtual const char* type_string() { return "ciObject"; }
duke@435 95
duke@435 96 void set_ident(uint id);
duke@435 97 public:
duke@435 98 // The klass of this ciObject.
duke@435 99 ciKlass* klass();
duke@435 100
duke@435 101 // A number unique to this object.
duke@435 102 uint ident();
duke@435 103
duke@435 104 // Are two ciObjects equal?
duke@435 105 bool equals(ciObject* obj);
duke@435 106
duke@435 107 // A hash value for the convenience of compilers.
duke@435 108 int hash();
duke@435 109
jrose@1424 110 // Tells if this oop has an encoding as a constant.
kvn@2933 111 // True if is_perm is true.
jrose@1424 112 // Also true if ScavengeRootsInCode is non-zero.
duke@435 113 // If it does not have an encoding, the compiler is responsible for
duke@435 114 // making other arrangements for dealing with the oop.
jrose@1424 115 // See ciEnv::make_array
jrose@1424 116 bool can_be_constant();
jrose@1424 117
jrose@1424 118 // Tells if this oop should be made a constant.
kvn@2933 119 // True if is_perm is true or ScavengeRootsInCode > 1.
jrose@1424 120 bool should_be_constant();
duke@435 121
duke@435 122 // Is this object guaranteed to be in the permanent part of the heap?
duke@435 123 // If so, CollectedHeap::can_elide_permanent_oop_store_barriers is relevant.
duke@435 124 // If the answer is false, no guarantees are made.
duke@435 125 bool is_perm() { return (_ident & PERM_FLAG) != 0; }
duke@435 126
jrose@1424 127 // Might this object possibly move during a scavenge operation?
jrose@1424 128 // If the answer is true and ScavengeRootsInCode==0, the oop cannot be embedded in code.
jrose@1424 129 bool is_scavengable() { return (_ident & SCAVENGABLE_FLAG) != 0; }
jrose@1424 130
duke@435 131 // The address which the compiler should embed into the
duke@435 132 // generated code to represent this oop. This address
duke@435 133 // is not the true address of the oop -- it will get patched
duke@435 134 // during nmethod creation.
duke@435 135 //
duke@435 136 // Usage note: no address arithmetic allowed. Oop must
duke@435 137 // be registered with the oopRecorder.
jrose@1424 138 jobject constant_encoding();
duke@435 139
duke@435 140 // What kind of ciObject is this?
duke@435 141 virtual bool is_null_object() const { return false; }
twisti@1573 142 virtual bool is_call_site() const { return false; }
twisti@1572 143 virtual bool is_cpcache() const { return false; }
duke@435 144 virtual bool is_instance() { return false; }
duke@435 145 virtual bool is_method() { return false; }
duke@435 146 virtual bool is_method_data() { return false; }
twisti@1573 147 virtual bool is_method_handle() const { return false; }
duke@435 148 virtual bool is_array() { return false; }
duke@435 149 virtual bool is_obj_array() { return false; }
duke@435 150 virtual bool is_type_array() { return false; }
duke@435 151 virtual bool is_symbol() { return false; }
duke@435 152 virtual bool is_type() { return false; }
duke@435 153 virtual bool is_return_address() { return false; }
duke@435 154 virtual bool is_klass() { return false; }
duke@435 155 virtual bool is_instance_klass() { return false; }
duke@435 156 virtual bool is_method_klass() { return false; }
duke@435 157 virtual bool is_array_klass() { return false; }
duke@435 158 virtual bool is_obj_array_klass() { return false; }
duke@435 159 virtual bool is_type_array_klass() { return false; }
duke@435 160 virtual bool is_symbol_klass() { return false; }
duke@435 161 virtual bool is_klass_klass() { return false; }
duke@435 162 virtual bool is_instance_klass_klass() { return false; }
duke@435 163 virtual bool is_array_klass_klass() { return false; }
duke@435 164 virtual bool is_obj_array_klass_klass() { return false; }
duke@435 165 virtual bool is_type_array_klass_klass() { return false; }
duke@435 166
duke@435 167 // Is this a type or value which has no associated class?
duke@435 168 // It is true of primitive types and null objects.
duke@435 169 virtual bool is_classless() const { return false; }
duke@435 170
duke@435 171 // Is this ciObject a Java Language Object? That is,
duke@435 172 // is the ciObject an instance or an array
duke@435 173 virtual bool is_java_object() { return false; }
duke@435 174
duke@435 175 // Does this ciObject represent a Java Language class?
duke@435 176 // That is, is the ciObject an instanceKlass or arrayKlass?
duke@435 177 virtual bool is_java_klass() { return false; }
duke@435 178
duke@435 179 // Is this ciObject the ciInstanceKlass representing
duke@435 180 // java.lang.Object()?
duke@435 181 virtual bool is_java_lang_Object() { return false; }
duke@435 182
duke@435 183 // Does this ciObject refer to a real oop in the VM?
duke@435 184 //
duke@435 185 // Note: some ciObjects refer to oops which have yet to be
duke@435 186 // created. We refer to these as "unloaded". Specifically,
duke@435 187 // there are unloaded ciMethods, ciObjArrayKlasses, and
duke@435 188 // ciInstanceKlasses. By convention the ciNullObject is
duke@435 189 // considered loaded, and primitive types are considered loaded.
duke@435 190 bool is_loaded() const {
duke@435 191 return handle() != NULL || is_classless();
duke@435 192 }
duke@435 193
duke@435 194 // Subclass casting with assertions.
duke@435 195 ciNullObject* as_null_object() {
duke@435 196 assert(is_null_object(), "bad cast");
duke@435 197 return (ciNullObject*)this;
duke@435 198 }
twisti@1573 199 ciCallSite* as_call_site() {
twisti@1573 200 assert(is_call_site(), "bad cast");
twisti@1573 201 return (ciCallSite*) this;
twisti@1573 202 }
twisti@1572 203 ciCPCache* as_cpcache() {
twisti@1572 204 assert(is_cpcache(), "bad cast");
twisti@1572 205 return (ciCPCache*) this;
twisti@1572 206 }
duke@435 207 ciInstance* as_instance() {
duke@435 208 assert(is_instance(), "bad cast");
duke@435 209 return (ciInstance*)this;
duke@435 210 }
duke@435 211 ciMethod* as_method() {
duke@435 212 assert(is_method(), "bad cast");
duke@435 213 return (ciMethod*)this;
duke@435 214 }
duke@435 215 ciMethodData* as_method_data() {
duke@435 216 assert(is_method_data(), "bad cast");
duke@435 217 return (ciMethodData*)this;
duke@435 218 }
twisti@1573 219 ciMethodHandle* as_method_handle() {
twisti@1573 220 assert(is_method_handle(), "bad cast");
twisti@1573 221 return (ciMethodHandle*) this;
twisti@1573 222 }
duke@435 223 ciArray* as_array() {
duke@435 224 assert(is_array(), "bad cast");
duke@435 225 return (ciArray*)this;
duke@435 226 }
duke@435 227 ciObjArray* as_obj_array() {
duke@435 228 assert(is_obj_array(), "bad cast");
duke@435 229 return (ciObjArray*)this;
duke@435 230 }
duke@435 231 ciTypeArray* as_type_array() {
duke@435 232 assert(is_type_array(), "bad cast");
duke@435 233 return (ciTypeArray*)this;
duke@435 234 }
duke@435 235 ciSymbol* as_symbol() {
duke@435 236 assert(is_symbol(), "bad cast");
duke@435 237 return (ciSymbol*)this;
duke@435 238 }
duke@435 239 ciType* as_type() {
duke@435 240 assert(is_type(), "bad cast");
duke@435 241 return (ciType*)this;
duke@435 242 }
duke@435 243 ciReturnAddress* as_return_address() {
duke@435 244 assert(is_return_address(), "bad cast");
duke@435 245 return (ciReturnAddress*)this;
duke@435 246 }
duke@435 247 ciKlass* as_klass() {
duke@435 248 assert(is_klass(), "bad cast");
duke@435 249 return (ciKlass*)this;
duke@435 250 }
duke@435 251 ciInstanceKlass* as_instance_klass() {
duke@435 252 assert(is_instance_klass(), "bad cast");
duke@435 253 return (ciInstanceKlass*)this;
duke@435 254 }
duke@435 255 ciMethodKlass* as_method_klass() {
duke@435 256 assert(is_method_klass(), "bad cast");
duke@435 257 return (ciMethodKlass*)this;
duke@435 258 }
duke@435 259 ciArrayKlass* as_array_klass() {
duke@435 260 assert(is_array_klass(), "bad cast");
duke@435 261 return (ciArrayKlass*)this;
duke@435 262 }
duke@435 263 ciObjArrayKlass* as_obj_array_klass() {
duke@435 264 assert(is_obj_array_klass(), "bad cast");
duke@435 265 return (ciObjArrayKlass*)this;
duke@435 266 }
duke@435 267 ciTypeArrayKlass* as_type_array_klass() {
duke@435 268 assert(is_type_array_klass(), "bad cast");
duke@435 269 return (ciTypeArrayKlass*)this;
duke@435 270 }
duke@435 271 ciKlassKlass* as_klass_klass() {
duke@435 272 assert(is_klass_klass(), "bad cast");
duke@435 273 return (ciKlassKlass*)this;
duke@435 274 }
duke@435 275 ciInstanceKlassKlass* as_instance_klass_klass() {
duke@435 276 assert(is_instance_klass_klass(), "bad cast");
duke@435 277 return (ciInstanceKlassKlass*)this;
duke@435 278 }
duke@435 279 ciArrayKlassKlass* as_array_klass_klass() {
duke@435 280 assert(is_array_klass_klass(), "bad cast");
duke@435 281 return (ciArrayKlassKlass*)this;
duke@435 282 }
duke@435 283 ciObjArrayKlassKlass* as_obj_array_klass_klass() {
duke@435 284 assert(is_obj_array_klass_klass(), "bad cast");
duke@435 285 return (ciObjArrayKlassKlass*)this;
duke@435 286 }
duke@435 287 ciTypeArrayKlassKlass* as_type_array_klass_klass() {
duke@435 288 assert(is_type_array_klass_klass(), "bad cast");
duke@435 289 return (ciTypeArrayKlassKlass*)this;
duke@435 290 }
duke@435 291
duke@435 292 // Print debugging output about this ciObject.
duke@435 293 void print(outputStream* st = tty);
duke@435 294
duke@435 295 // Print debugging output about the oop this ciObject represents.
duke@435 296 void print_oop(outputStream* st = tty);
duke@435 297 };
stefank@2314 298
stefank@2314 299 #endif // SHARE_VM_CI_CIOBJECT_HPP

mercurial