Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/ci/ciObject.cpp
32285 views
/*1* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "ci/ciObject.hpp"26#include "ci/ciUtilities.hpp"27#include "gc_interface/collectedHeap.inline.hpp"28#include "oops/oop.inline2.hpp"2930// ciObject31//32// This class represents an oop in the HotSpot virtual machine.33// Its subclasses are structured in a hierarchy which mirrors34// an aggregate of the VM's oop and klass hierarchies (see35// oopHierarchy.hpp). Each instance of ciObject holds a handle36// to a corresponding oop on the VM side and provides routines37// for accessing the information in its oop. By using the ciObject38// hierarchy for accessing oops in the VM, the compiler ensures39// that it is safe with respect to garbage collection; that is,40// GC and compilation can proceed independently without41// interference.42//43// Within the VM, the oop and klass hierarchies are separate.44// The compiler interface does not preserve this separation --45// the distinction between `Klass*' and `Klass' are not46// reflected in the interface and instead the Klass hierarchy47// is directly modeled as the subclasses of ciKlass.4849// ------------------------------------------------------------------50// ciObject::ciObject51ciObject::ciObject(oop o) {52ASSERT_IN_VM;53if (ciObjectFactory::is_initialized()) {54_handle = JNIHandles::make_local(o);55} else {56_handle = JNIHandles::make_global(o);57}58_klass = NULL;59init_flags_from(o);60}6162// ------------------------------------------------------------------63// ciObject::ciObject64//65ciObject::ciObject(Handle h) {66ASSERT_IN_VM;67if (ciObjectFactory::is_initialized()) {68_handle = JNIHandles::make_local(h());69} else {70_handle = JNIHandles::make_global(h);71}72_klass = NULL;73init_flags_from(h());74}7576// ------------------------------------------------------------------77// ciObject::ciObject78//79// Unloaded klass/method variant. `klass' is the klass of the unloaded80// klass/method, if that makes sense.81ciObject::ciObject(ciKlass* klass) {82ASSERT_IN_VM;83assert(klass != NULL, "must supply klass");84_handle = NULL;85_klass = klass;86}8788// ------------------------------------------------------------------89// ciObject::ciObject90//91// NULL variant. Used only by ciNullObject.92ciObject::ciObject() {93ASSERT_IN_VM;94_handle = NULL;95_klass = NULL;96}9798// ------------------------------------------------------------------99// ciObject::klass100//101// Get the ciKlass of this ciObject.102ciKlass* ciObject::klass() {103if (_klass == NULL) {104if (_handle == NULL) {105// When both _klass and _handle are NULL, we are dealing106// with the distinguished instance of ciNullObject.107// No one should ask it for its klass.108assert(is_null_object(), "must be null object");109ShouldNotReachHere();110return NULL;111}112113GUARDED_VM_ENTRY(114oop o = get_oop();115_klass = CURRENT_ENV->get_klass(o->klass());116);117}118return _klass;119}120121// ------------------------------------------------------------------122// ciObject::equals123//124// Are two ciObjects equal?125bool ciObject::equals(ciObject* obj) {126return (this == obj);127}128129// ------------------------------------------------------------------130// ciObject::hash131//132// A hash value for the convenience of compilers.133//134// Implementation note: we use the address of the ciObject as the135// basis for the hash. Use the _ident field, which is well-behaved.136int ciObject::hash() {137return ident() * 31;138}139140// ------------------------------------------------------------------141// ciObject::constant_encoding142//143// The address which the compiler should embed into the144// generated code to represent this oop. This address145// is not the true address of the oop -- it will get patched146// during nmethod creation.147//148//149//150// Implementation note: we use the handle as the encoding. The151// nmethod constructor resolves the handle and patches in the oop.152//153// This method should be changed to return an generified address154// to discourage use of the JNI handle.155jobject ciObject::constant_encoding() {156assert(is_null_object() || handle() != NULL, "cannot embed null pointer");157assert(can_be_constant(), "oop must be NULL or perm");158return handle();159}160161// ------------------------------------------------------------------162// ciObject::can_be_constant163bool ciObject::can_be_constant() {164if (ScavengeRootsInCode >= 1) return true; // now everybody can encode as a constant165return handle() == NULL;166}167168// ------------------------------------------------------------------169// ciObject::should_be_constant()170bool ciObject::should_be_constant() {171if (ScavengeRootsInCode >= 2) return true; // force everybody to be a constant172if (is_null_object()) return true;173174ciEnv* env = CURRENT_ENV;175176// We want Strings and Classes to be embeddable by default since177// they used to be in the perm world. Not all Strings used to be178// embeddable but there's no easy way to distinguish the interned179// from the regulars ones so just treat them all that way.180if (klass() == env->String_klass() || klass() == env->Class_klass()) {181return true;182}183if (EnableInvokeDynamic &&184(klass()->is_subclass_of(env->MethodHandle_klass()) ||185klass()->is_subclass_of(env->CallSite_klass()))) {186assert(ScavengeRootsInCode >= 1, "must be");187// We want to treat these aggressively.188return true;189}190191return handle() == NULL;192}193194// ------------------------------------------------------------------195// ciObject::should_be_constant()196void ciObject::init_flags_from(oop x) {197int flags = 0;198if (x != NULL) {199assert(Universe::heap()->is_in_reserved(x), "must be");200if (x->is_scavengable())201flags |= SCAVENGABLE_FLAG;202}203_ident |= flags;204}205206// ------------------------------------------------------------------207// ciObject::print208//209// Print debugging output about this ciObject.210//211// Implementation note: dispatch to the virtual print_impl behavior212// for this ciObject.213void ciObject::print(outputStream* st) {214st->print("<%s", type_string());215GUARDED_VM_ENTRY(print_impl(st);)216st->print(" ident=%d %s address=" INTPTR_FORMAT ">", ident(),217is_scavengable() ? "SCAVENGABLE" : "",218p2i((address)this));219}220221// ------------------------------------------------------------------222// ciObject::print_oop223//224// Print debugging output about the oop this ciObject represents.225void ciObject::print_oop(outputStream* st) {226if (is_null_object()) {227st->print_cr("NULL");228} else if (!is_loaded()) {229st->print_cr("UNLOADED");230} else {231GUARDED_VM_ENTRY(get_oop()->print_on(st);)232}233}234235236