src/share/vm/ci/ciObject.hpp

Thu, 24 May 2018 18:41:44 +0800

author
aoqi
date
Thu, 24 May 2018 18:41:44 +0800
changeset 8856
ac27a9c85bea
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_CI_CIOBJECT_HPP
aoqi@0 26 #define SHARE_VM_CI_CIOBJECT_HPP
aoqi@0 27
aoqi@0 28 #include "ci/ciBaseObject.hpp"
aoqi@0 29 #include "ci/ciClassList.hpp"
aoqi@0 30 #include "memory/allocation.hpp"
aoqi@0 31 #include "runtime/handles.hpp"
aoqi@0 32 #include "runtime/jniHandles.hpp"
aoqi@0 33
aoqi@0 34 // ciObject
aoqi@0 35 //
aoqi@0 36 // This class represents an oop in the HotSpot virtual machine.
aoqi@0 37 // Its subclasses are structured in a hierarchy which mirrors
aoqi@0 38 // an aggregate of the VM's oop and klass hierarchies (see
aoqi@0 39 // oopHierarchy.hpp). Each instance of ciObject holds a handle
aoqi@0 40 // to a corresponding oop on the VM side and provides routines
aoqi@0 41 // for accessing the information in its oop. By using the ciObject
aoqi@0 42 // hierarchy for accessing oops in the VM, the compiler ensures
aoqi@0 43 // that it is safe with respect to garbage collection; that is,
aoqi@0 44 // GC and compilation can proceed independently without
aoqi@0 45 // interference.
aoqi@0 46 //
aoqi@0 47 // Within the VM, the oop and klass hierarchies are separate.
aoqi@0 48 // The compiler interface does not preserve this separation --
aoqi@0 49 // the distinction between `Klass*' and `Klass' are not
aoqi@0 50 // reflected in the interface and instead the Klass hierarchy
aoqi@0 51 // is directly modeled as the subclasses of ciKlass.
aoqi@0 52 class ciObject : public ciBaseObject {
aoqi@0 53 CI_PACKAGE_ACCESS
aoqi@0 54 friend class ciEnv;
aoqi@0 55
aoqi@0 56 private:
aoqi@0 57 // A JNI handle referring to an oop in the VM. This
aoqi@0 58 // handle may, in a small set of cases, correctly be NULL.
aoqi@0 59 jobject _handle;
aoqi@0 60 ciKlass* _klass;
aoqi@0 61
aoqi@0 62 protected:
aoqi@0 63 ciObject();
aoqi@0 64 ciObject(oop o);
aoqi@0 65 ciObject(Handle h);
aoqi@0 66 ciObject(ciKlass* klass);
aoqi@0 67
aoqi@0 68 jobject handle() const { return _handle; }
aoqi@0 69 // Get the VM oop that this object holds.
aoqi@0 70 oop get_oop() const {
aoqi@0 71 assert(_handle != NULL, "null oop");
aoqi@0 72 return JNIHandles::resolve_non_null(_handle);
aoqi@0 73 }
aoqi@0 74
aoqi@0 75 void init_flags_from(oop x);
aoqi@0 76
aoqi@0 77 // Virtual behavior of the print() method.
aoqi@0 78 virtual void print_impl(outputStream* st) {}
aoqi@0 79
aoqi@0 80 virtual const char* type_string() { return "ciObject"; }
aoqi@0 81
aoqi@0 82 public:
aoqi@0 83 // The klass of this ciObject.
aoqi@0 84 ciKlass* klass();
aoqi@0 85
aoqi@0 86 // Are two ciObjects equal?
aoqi@0 87 bool equals(ciObject* obj);
aoqi@0 88
aoqi@0 89 // A hash value for the convenience of compilers.
aoqi@0 90 int hash();
aoqi@0 91
aoqi@0 92 // Tells if this oop has an encoding as a constant.
aoqi@0 93 // True if is_perm is true.
aoqi@0 94 // Also true if ScavengeRootsInCode is non-zero.
aoqi@0 95 // If it does not have an encoding, the compiler is responsible for
aoqi@0 96 // making other arrangements for dealing with the oop.
aoqi@0 97 // See ciEnv::make_array
aoqi@0 98 bool can_be_constant();
aoqi@0 99
aoqi@0 100 // Tells if this oop should be made a constant.
aoqi@0 101 // True if is_perm is true or ScavengeRootsInCode > 1.
aoqi@0 102 bool should_be_constant();
aoqi@0 103
aoqi@0 104 // Might this object possibly move during a scavenge operation?
aoqi@0 105 // If the answer is true and ScavengeRootsInCode==0, the oop cannot be embedded in code.
aoqi@0 106 bool is_scavengable() { return (_ident & SCAVENGABLE_FLAG) != 0; }
aoqi@0 107
aoqi@0 108 // The address which the compiler should embed into the
aoqi@0 109 // generated code to represent this oop. This address
aoqi@0 110 // is not the true address of the oop -- it will get patched
aoqi@0 111 // during nmethod creation.
aoqi@0 112 //
aoqi@0 113 // Usage note: no address arithmetic allowed. Oop must
aoqi@0 114 // be registered with the oopRecorder.
aoqi@0 115 jobject constant_encoding();
aoqi@0 116
aoqi@0 117 virtual bool is_object() const { return true; }
aoqi@0 118
aoqi@0 119 // What kind of ciObject is this?
aoqi@0 120 virtual bool is_null_object() const { return false; }
aoqi@0 121 virtual bool is_call_site() const { return false; }
aoqi@0 122 virtual bool is_cpcache() const { return false; }
aoqi@0 123 virtual bool is_instance() { return false; }
aoqi@0 124 virtual bool is_member_name() const { return false; }
aoqi@0 125 virtual bool is_method_handle() const { return false; }
aoqi@0 126 virtual bool is_method_type() const { return false; }
aoqi@0 127 virtual bool is_array() { return false; }
aoqi@0 128 virtual bool is_obj_array() { return false; }
aoqi@0 129 virtual bool is_type_array() { return false; }
aoqi@0 130
aoqi@0 131 // Is this a type or value which has no associated class?
aoqi@0 132 // It is true of primitive types and null objects.
aoqi@0 133 virtual bool is_classless() const { return false; }
aoqi@0 134 virtual void dump_replay_data(outputStream* st) { /* do nothing */ }
aoqi@0 135
aoqi@0 136 // Note: some ciObjects refer to oops which have yet to be created.
aoqi@0 137 // We refer to these as "unloaded". Specifically, there are
aoqi@0 138 // unloaded instances of java.lang.Class,
aoqi@0 139 // java.lang.invoke.MethodHandle, and java.lang.invoke.MethodType.
aoqi@0 140 // By convention the ciNullObject is considered loaded, and
aoqi@0 141 // primitive types are considered loaded.
aoqi@0 142 bool is_loaded() const {
aoqi@0 143 return handle() != NULL || is_classless();
aoqi@0 144 }
aoqi@0 145
aoqi@0 146 // Subclass casting with assertions.
aoqi@0 147 ciNullObject* as_null_object() {
aoqi@0 148 assert(is_null_object(), "bad cast");
aoqi@0 149 return (ciNullObject*)this;
aoqi@0 150 }
aoqi@0 151 ciCallSite* as_call_site() {
aoqi@0 152 assert(is_call_site(), "bad cast");
aoqi@0 153 return (ciCallSite*)this;
aoqi@0 154 }
aoqi@0 155 ciInstance* as_instance() {
aoqi@0 156 assert(is_instance(), "bad cast");
aoqi@0 157 return (ciInstance*)this;
aoqi@0 158 }
aoqi@0 159 ciMemberName* as_member_name() {
aoqi@0 160 assert(is_member_name(), "bad cast");
aoqi@0 161 return (ciMemberName*)this;
aoqi@0 162 }
aoqi@0 163 ciMethodHandle* as_method_handle() {
aoqi@0 164 assert(is_method_handle(), "bad cast");
aoqi@0 165 return (ciMethodHandle*)this;
aoqi@0 166 }
aoqi@0 167 ciMethodType* as_method_type() {
aoqi@0 168 assert(is_method_type(), "bad cast");
aoqi@0 169 return (ciMethodType*)this;
aoqi@0 170 }
aoqi@0 171 ciArray* as_array() {
aoqi@0 172 assert(is_array(), "bad cast");
aoqi@0 173 return (ciArray*)this;
aoqi@0 174 }
aoqi@0 175 ciObjArray* as_obj_array() {
aoqi@0 176 assert(is_obj_array(), "bad cast");
aoqi@0 177 return (ciObjArray*)this;
aoqi@0 178 }
aoqi@0 179 ciTypeArray* as_type_array() {
aoqi@0 180 assert(is_type_array(), "bad cast");
aoqi@0 181 return (ciTypeArray*)this;
aoqi@0 182 }
aoqi@0 183
aoqi@0 184 // Print debugging output about this ciObject.
aoqi@0 185 void print(outputStream* st);
aoqi@0 186 void print() { print(tty); } // GDB cannot handle default arguments
aoqi@0 187
aoqi@0 188 // Print debugging output about the oop this ciObject represents.
aoqi@0 189 void print_oop(outputStream* st = tty);
aoqi@0 190 };
aoqi@0 191
aoqi@0 192 #endif // SHARE_VM_CI_CIOBJECT_HPP

mercurial