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