0N/A/*
2223N/A * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "ci/ciConstant.hpp"
1879N/A#include "ci/ciField.hpp"
1879N/A#include "ci/ciInstance.hpp"
1879N/A#include "ci/ciInstanceKlass.hpp"
1879N/A#include "ci/ciUtilities.hpp"
1879N/A#include "classfile/systemDictionary.hpp"
1879N/A#include "oops/oop.inline.hpp"
0N/A
0N/A// ciInstance
0N/A//
0N/A// This class represents an instanceOop in the HotSpot virtual
0N/A// machine.
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciObject::java_mirror_type
0N/AciType* ciInstance::java_mirror_type() {
0N/A VM_ENTRY_MARK;
0N/A oop m = get_oop();
0N/A // Return NULL if it is not java.lang.Class.
1142N/A if (m == NULL || m->klass() != SystemDictionary::Class_klass()) {
0N/A return NULL;
0N/A }
0N/A // Return either a primitive type or a klass.
0N/A if (java_lang_Class::is_primitive(m)) {
0N/A return ciType::make(java_lang_Class::primitive_type(m));
0N/A } else {
0N/A klassOop k = java_lang_Class::as_klassOop(m);
0N/A assert(k != NULL, "");
0N/A return CURRENT_THREAD_ENV->get_object(k)->as_klass();
0N/A }
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciInstance::field_value
0N/A//
0N/A// Constant value of a field.
0N/AciConstant ciInstance::field_value(ciField* field) {
0N/A assert(is_loaded() &&
0N/A field->holder()->is_loaded() &&
0N/A klass()->is_subclass_of(field->holder()),
0N/A "invalid access");
0N/A VM_ENTRY_MARK;
0N/A ciConstant result;
2314N/A Handle obj = get_oop();
2314N/A assert(!obj.is_null(), "bad oop");
0N/A BasicType field_btype = field->type()->basic_type();
0N/A int offset = field->offset();
0N/A
0N/A switch(field_btype) {
0N/A case T_BYTE:
0N/A return ciConstant(field_btype, obj->byte_field(offset));
0N/A break;
0N/A case T_CHAR:
0N/A return ciConstant(field_btype, obj->char_field(offset));
0N/A break;
0N/A case T_SHORT:
0N/A return ciConstant(field_btype, obj->short_field(offset));
0N/A break;
0N/A case T_BOOLEAN:
0N/A return ciConstant(field_btype, obj->bool_field(offset));
0N/A break;
0N/A case T_INT:
0N/A return ciConstant(field_btype, obj->int_field(offset));
0N/A break;
0N/A case T_FLOAT:
0N/A return ciConstant(obj->float_field(offset));
0N/A break;
0N/A case T_DOUBLE:
0N/A return ciConstant(obj->double_field(offset));
0N/A break;
0N/A case T_LONG:
0N/A return ciConstant(obj->long_field(offset));
0N/A break;
0N/A case T_OBJECT:
0N/A case T_ARRAY:
0N/A {
0N/A oop o = obj->obj_field(offset);
0N/A
0N/A // A field will be "constant" if it is known always to be
0N/A // a non-null reference to an instance of a particular class,
0N/A // or to a particular array. This can happen even if the instance
0N/A // or array is not perm. In such a case, an "unloaded" ciArray
0N/A // or ciInstance is created. The compiler may be able to use
0N/A // information about the object's class (which is exact) or length.
0N/A
0N/A if (o == NULL) {
0N/A return ciConstant(field_btype, ciNullObject::make());
0N/A } else {
0N/A return ciConstant(field_btype, CURRENT_ENV->get_object(o));
0N/A }
0N/A }
0N/A }
0N/A ShouldNotReachHere();
0N/A // to shut up the compiler
0N/A return ciConstant();
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciInstance::field_value_by_offset
0N/A//
0N/A// Constant value of a field at the specified offset.
0N/AciConstant ciInstance::field_value_by_offset(int field_offset) {
0N/A ciInstanceKlass* ik = klass()->as_instance_klass();
0N/A ciField* field = ik->get_field_by_offset(field_offset, false);
0N/A return field_value(field);
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciInstance::print_impl
0N/A//
0N/A// Implementation of the print method.
0N/Avoid ciInstance::print_impl(outputStream* st) {
0N/A st->print(" type=");
0N/A klass()->print(st);
0N/A}
2223N/A
2223N/A
2223N/AciKlass* ciInstance::java_lang_Class_klass() {
2223N/A VM_ENTRY_MARK;
2223N/A return CURRENT_ENV->get_object(java_lang_Class::as_klassOop(get_oop()))->as_klass();
2223N/A}