duke@435: /* coleenp@4037: * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_CI_CIOBJECT_HPP stefank@2314: #define SHARE_VM_CI_CIOBJECT_HPP stefank@2314: coleenp@4037: #include "ci/ciBaseObject.hpp" stefank@2314: #include "ci/ciClassList.hpp" stefank@2314: #include "memory/allocation.hpp" stefank@2314: #include "runtime/handles.hpp" stefank@2314: #include "runtime/jniHandles.hpp" stefank@2314: duke@435: // ciObject duke@435: // duke@435: // This class represents an oop in the HotSpot virtual machine. duke@435: // Its subclasses are structured in a hierarchy which mirrors duke@435: // an aggregate of the VM's oop and klass hierarchies (see duke@435: // oopHierarchy.hpp). Each instance of ciObject holds a handle duke@435: // to a corresponding oop on the VM side and provides routines duke@435: // for accessing the information in its oop. By using the ciObject duke@435: // hierarchy for accessing oops in the VM, the compiler ensures duke@435: // that it is safe with respect to garbage collection; that is, duke@435: // GC and compilation can proceed independently without duke@435: // interference. duke@435: // duke@435: // Within the VM, the oop and klass hierarchies are separate. duke@435: // The compiler interface does not preserve this separation -- coleenp@4037: // the distinction between `Klass*' and `Klass' are not duke@435: // reflected in the interface and instead the Klass hierarchy duke@435: // is directly modeled as the subclasses of ciKlass. coleenp@4037: class ciObject : public ciBaseObject { duke@435: CI_PACKAGE_ACCESS duke@435: friend class ciEnv; duke@435: duke@435: private: duke@435: // A JNI handle referring to an oop in the VM. This duke@435: // handle may, in a small set of cases, correctly be NULL. duke@435: jobject _handle; duke@435: ciKlass* _klass; duke@435: duke@435: protected: duke@435: ciObject(); duke@435: ciObject(oop o); duke@435: ciObject(Handle h); duke@435: ciObject(ciKlass* klass); duke@435: duke@435: jobject handle() const { return _handle; } duke@435: // Get the VM oop that this object holds. duke@435: oop get_oop() const { duke@435: assert(_handle != NULL, "null oop"); duke@435: return JNIHandles::resolve_non_null(_handle); duke@435: } duke@435: coleenp@4037: void init_flags_from(oop x); duke@435: duke@435: // Virtual behavior of the print() method. duke@435: virtual void print_impl(outputStream* st) {} duke@435: duke@435: virtual const char* type_string() { return "ciObject"; } duke@435: duke@435: public: duke@435: // The klass of this ciObject. duke@435: ciKlass* klass(); duke@435: duke@435: // Are two ciObjects equal? duke@435: bool equals(ciObject* obj); duke@435: duke@435: // A hash value for the convenience of compilers. duke@435: int hash(); duke@435: jrose@1424: // Tells if this oop has an encoding as a constant. kvn@2933: // True if is_perm is true. jrose@1424: // Also true if ScavengeRootsInCode is non-zero. duke@435: // If it does not have an encoding, the compiler is responsible for duke@435: // making other arrangements for dealing with the oop. jrose@1424: // See ciEnv::make_array jrose@1424: bool can_be_constant(); jrose@1424: jrose@1424: // Tells if this oop should be made a constant. kvn@2933: // True if is_perm is true or ScavengeRootsInCode > 1. jrose@1424: bool should_be_constant(); duke@435: jrose@1424: // Might this object possibly move during a scavenge operation? jrose@1424: // If the answer is true and ScavengeRootsInCode==0, the oop cannot be embedded in code. jrose@1424: bool is_scavengable() { return (_ident & SCAVENGABLE_FLAG) != 0; } jrose@1424: duke@435: // The address which the compiler should embed into the duke@435: // generated code to represent this oop. This address duke@435: // is not the true address of the oop -- it will get patched duke@435: // during nmethod creation. duke@435: // duke@435: // Usage note: no address arithmetic allowed. Oop must duke@435: // be registered with the oopRecorder. jrose@1424: jobject constant_encoding(); duke@435: coleenp@4037: virtual bool is_object() const { return true; } coleenp@4037: duke@435: // What kind of ciObject is this? twisti@3969: virtual bool is_null_object() const { return false; } twisti@3969: virtual bool is_call_site() const { return false; } twisti@3969: virtual bool is_cpcache() const { return false; } duke@435: virtual bool is_instance() { return false; } twisti@3969: virtual bool is_member_name() const { return false; } twisti@3969: virtual bool is_method_handle() const { return false; } twisti@4133: virtual bool is_method_type() const { return false; } duke@435: virtual bool is_array() { return false; } duke@435: virtual bool is_obj_array() { return false; } duke@435: virtual bool is_type_array() { return false; } duke@435: duke@435: // Is this a type or value which has no associated class? duke@435: // It is true of primitive types and null objects. duke@435: virtual bool is_classless() const { return false; } minqi@4267: virtual void dump_replay_data(outputStream* st) { /* do nothing */ } duke@435: coleenp@4037: // Note: some ciObjects refer to oops which have yet to be created. coleenp@4037: // We refer to these as "unloaded". Specifically, there are coleenp@4037: // unloaded instances of java.lang.Class, coleenp@4037: // java.lang.invoke.MethodHandle, and java.lang.invoke.MethodType. coleenp@4037: // By convention the ciNullObject is considered loaded, and coleenp@4037: // primitive types are considered loaded. duke@435: bool is_loaded() const { duke@435: return handle() != NULL || is_classless(); duke@435: } duke@435: duke@435: // Subclass casting with assertions. twisti@4133: ciNullObject* as_null_object() { duke@435: assert(is_null_object(), "bad cast"); duke@435: return (ciNullObject*)this; duke@435: } twisti@4133: ciCallSite* as_call_site() { twisti@1573: assert(is_call_site(), "bad cast"); twisti@4133: return (ciCallSite*)this; twisti@1573: } twisti@4133: ciInstance* as_instance() { duke@435: assert(is_instance(), "bad cast"); duke@435: return (ciInstance*)this; duke@435: } twisti@4133: ciMemberName* as_member_name() { twisti@3969: assert(is_member_name(), "bad cast"); twisti@3969: return (ciMemberName*)this; twisti@3969: } twisti@4133: ciMethodHandle* as_method_handle() { twisti@1573: assert(is_method_handle(), "bad cast"); twisti@4133: return (ciMethodHandle*)this; twisti@1573: } twisti@4133: ciMethodType* as_method_type() { twisti@4133: assert(is_method_type(), "bad cast"); twisti@4133: return (ciMethodType*)this; twisti@4133: } twisti@4133: ciArray* as_array() { duke@435: assert(is_array(), "bad cast"); duke@435: return (ciArray*)this; duke@435: } twisti@4133: ciObjArray* as_obj_array() { duke@435: assert(is_obj_array(), "bad cast"); duke@435: return (ciObjArray*)this; duke@435: } twisti@4133: ciTypeArray* as_type_array() { duke@435: assert(is_type_array(), "bad cast"); duke@435: return (ciTypeArray*)this; duke@435: } duke@435: duke@435: // Print debugging output about this ciObject. twisti@3969: void print(outputStream* st); twisti@3969: void print() { print(tty); } // GDB cannot handle default arguments duke@435: duke@435: // Print debugging output about the oop this ciObject represents. duke@435: void print_oop(outputStream* st = tty); duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_CI_CIOBJECT_HPP