duke@435: /* coleenp@4037: * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" coleenp@4037: #include "ci/ciEnv.hpp" stefank@2314: #include "ci/ciType.hpp" stefank@2314: #include "ci/ciUtilities.hpp" stefank@2314: #include "classfile/systemDictionary.hpp" stefank@2314: #include "oops/oop.inline.hpp" duke@435: duke@435: ciType* ciType::_basic_types[T_CONFLICT+1]; duke@435: duke@435: // ciType duke@435: // duke@435: // This class represents either a class (T_OBJECT), array (T_ARRAY), duke@435: // or one of the primitive types such as T_INT. duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciType::ciType duke@435: // coleenp@4037: ciType::ciType(BasicType basic_type) : ciMetadata() { duke@435: assert(basic_type >= T_BOOLEAN && basic_type <= T_CONFLICT, "range check"); duke@435: _basic_type = basic_type; duke@435: } duke@435: coleenp@4037: ciType::ciType(KlassHandle k) : ciMetadata(k()) { hseigel@4278: _basic_type = k()->oop_is_array() ? T_ARRAY : T_OBJECT; duke@435: } duke@435: duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciType::is_subtype_of duke@435: // duke@435: bool ciType::is_subtype_of(ciType* type) { duke@435: if (this == type) return true; duke@435: if (is_klass() && type->is_klass()) duke@435: return this->as_klass()->is_subtype_of(type->as_klass()); duke@435: return false; duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ twisti@4447: // ciType::name twisti@4447: // twisti@4447: // Return the name of this type twisti@4447: const char* ciType::name() { twisti@4447: if (is_primitive_type()) { twisti@4447: return type2name(basic_type()); twisti@4447: } else { twisti@4447: assert(is_klass(), "must be"); twisti@4447: return as_klass()->name()->as_utf8(); twisti@4447: } twisti@4447: } twisti@4447: twisti@4447: // ------------------------------------------------------------------ duke@435: // ciType::print_impl duke@435: // duke@435: // Implementation of the print method. duke@435: void ciType::print_impl(outputStream* st) { duke@435: st->print(" type="); duke@435: print_name_on(st); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciType::print_name duke@435: // duke@435: // Print the name of this type duke@435: void ciType::print_name_on(outputStream* st) { twisti@4447: ResourceMark rm; twisti@4447: st->print(name()); duke@435: } duke@435: duke@435: duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciType::java_mirror duke@435: // duke@435: ciInstance* ciType::java_mirror() { duke@435: VM_ENTRY_MARK; coleenp@4037: return CURRENT_THREAD_ENV->get_instance(Universe::java_mirror(basic_type())); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciType::box_klass duke@435: // duke@435: ciKlass* ciType::box_klass() { duke@435: if (!is_primitive_type()) return this->as_klass(); // reference types are "self boxing" duke@435: duke@435: // Void is "boxed" with a null. duke@435: if (basic_type() == T_VOID) return NULL; duke@435: duke@435: VM_ENTRY_MARK; coleenp@4037: return CURRENT_THREAD_ENV->get_instance_klass(SystemDictionary::box_klass(basic_type())); duke@435: } duke@435: duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciType::make duke@435: // duke@435: // Produce the ciType for a given primitive BasicType. duke@435: // As a bonus, produce the right reference type for T_OBJECT. duke@435: // Does not work on T_ARRAY. duke@435: ciType* ciType::make(BasicType t) { duke@435: // short, etc. duke@435: // Note: Bare T_ADDRESS means a raw pointer type, not a return_address. duke@435: assert((uint)t < T_CONFLICT+1, "range check"); never@1577: if (t == T_OBJECT) return ciEnv::_Object_klass; // java/lang/Object duke@435: assert(_basic_types[t] != NULL, "domain check"); duke@435: return _basic_types[t]; duke@435: } duke@435: duke@435: // ciReturnAddress duke@435: // duke@435: // This class represents the type of a specific return address in the duke@435: // bytecodes. duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciReturnAddress::ciReturnAddress duke@435: // duke@435: ciReturnAddress::ciReturnAddress(int bci) : ciType(T_ADDRESS) { duke@435: assert(0 <= bci, "bci cannot be negative"); duke@435: _bci = bci; duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciReturnAddress::print_impl duke@435: // duke@435: // Implementation of the print method. duke@435: void ciReturnAddress::print_impl(outputStream* st) { duke@435: st->print(" bci=%d", _bci); duke@435: } duke@435: duke@435: // ------------------------------------------------------------------ duke@435: // ciReturnAddress::make duke@435: ciReturnAddress* ciReturnAddress::make(int bci) { duke@435: GUARDED_VM_ENTRY(return CURRENT_ENV->get_return_address(bci);) duke@435: }