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