0N/A/*
1879N/A * Copyright (c) 2000, 2010, 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/ciType.hpp"
1879N/A#include "ci/ciUtilities.hpp"
1879N/A#include "classfile/systemDictionary.hpp"
1879N/A#include "oops/oop.inline.hpp"
0N/A
0N/AciType* ciType::_basic_types[T_CONFLICT+1];
0N/A
0N/A// ciType
0N/A//
0N/A// This class represents either a class (T_OBJECT), array (T_ARRAY),
0N/A// or one of the primitive types such as T_INT.
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciType::ciType
0N/A//
0N/AciType::ciType(BasicType basic_type) : ciObject() {
0N/A assert(basic_type >= T_BOOLEAN && basic_type <= T_CONFLICT, "range check");
0N/A assert(basic_type != T_OBJECT && basic_type != T_ARRAY, "not a reference type");
0N/A _basic_type = basic_type;
0N/A}
0N/A
0N/AciType::ciType(KlassHandle k) : ciObject(k) {
0N/A _basic_type = Klass::cast(k())->oop_is_array() ? T_ARRAY : T_OBJECT;
0N/A}
0N/A
0N/AciType::ciType(ciKlass* klass) : ciObject(klass) {
0N/A _basic_type = klass->is_array_klass_klass() ? T_ARRAY : T_OBJECT;
0N/A}
0N/A
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciType::is_subtype_of
0N/A//
0N/Abool ciType::is_subtype_of(ciType* type) {
0N/A if (this == type) return true;
0N/A if (is_klass() && type->is_klass())
0N/A return this->as_klass()->is_subtype_of(type->as_klass());
0N/A return false;
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
4174N/A// ciType::name
4174N/A//
4174N/A// Return the name of this type
4174N/Aconst char* ciType::name() {
4174N/A if (is_primitive_type()) {
4174N/A return type2name(basic_type());
4174N/A } else {
4174N/A assert(is_klass(), "must be");
4174N/A return as_klass()->name()->as_utf8();
4174N/A }
4174N/A}
4174N/A
4174N/A// ------------------------------------------------------------------
0N/A// ciType::print_impl
0N/A//
0N/A// Implementation of the print method.
0N/Avoid ciType::print_impl(outputStream* st) {
0N/A st->print(" type=");
0N/A print_name_on(st);
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciType::print_name
0N/A//
0N/A// Print the name of this type
0N/Avoid ciType::print_name_on(outputStream* st) {
4174N/A ResourceMark rm;
4174N/A st->print(name());
0N/A}
0N/A
0N/A
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciType::java_mirror
0N/A//
0N/AciInstance* ciType::java_mirror() {
0N/A VM_ENTRY_MARK;
0N/A return CURRENT_THREAD_ENV->get_object(Universe::java_mirror(basic_type()))->as_instance();
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciType::box_klass
0N/A//
0N/AciKlass* ciType::box_klass() {
0N/A if (!is_primitive_type()) return this->as_klass(); // reference types are "self boxing"
0N/A
0N/A // Void is "boxed" with a null.
0N/A if (basic_type() == T_VOID) return NULL;
0N/A
0N/A VM_ENTRY_MARK;
0N/A return CURRENT_THREAD_ENV->get_object(SystemDictionary::box_klass(basic_type()))->as_instance_klass();
0N/A}
0N/A
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciType::make
0N/A//
0N/A// Produce the ciType for a given primitive BasicType.
0N/A// As a bonus, produce the right reference type for T_OBJECT.
0N/A// Does not work on T_ARRAY.
0N/AciType* ciType::make(BasicType t) {
0N/A // short, etc.
0N/A // Note: Bare T_ADDRESS means a raw pointer type, not a return_address.
0N/A assert((uint)t < T_CONFLICT+1, "range check");
1142N/A if (t == T_OBJECT) return ciEnv::_Object_klass; // java/lang/Object
0N/A assert(_basic_types[t] != NULL, "domain check");
0N/A return _basic_types[t];
0N/A}
0N/A
0N/A// ciReturnAddress
0N/A//
0N/A// This class represents the type of a specific return address in the
0N/A// bytecodes.
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciReturnAddress::ciReturnAddress
0N/A//
0N/AciReturnAddress::ciReturnAddress(int bci) : ciType(T_ADDRESS) {
0N/A assert(0 <= bci, "bci cannot be negative");
0N/A _bci = bci;
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciReturnAddress::print_impl
0N/A//
0N/A// Implementation of the print method.
0N/Avoid ciReturnAddress::print_impl(outputStream* st) {
0N/A st->print(" bci=%d", _bci);
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciReturnAddress::make
0N/AciReturnAddress* ciReturnAddress::make(int bci) {
0N/A GUARDED_VM_ENTRY(return CURRENT_ENV->get_return_address(bci);)
0N/A}