src/share/vm/ci/ciType.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6680
78bbf4d43a14
parent 0
f90c822e73f8
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "ci/ciEnv.hpp"
aoqi@0 27 #include "ci/ciType.hpp"
aoqi@0 28 #include "ci/ciUtilities.hpp"
aoqi@0 29 #include "classfile/systemDictionary.hpp"
aoqi@0 30 #include "oops/oop.inline.hpp"
aoqi@0 31
aoqi@0 32 ciType* ciType::_basic_types[T_CONFLICT+1];
aoqi@0 33
aoqi@0 34 // ciType
aoqi@0 35 //
aoqi@0 36 // This class represents either a class (T_OBJECT), array (T_ARRAY),
aoqi@0 37 // or one of the primitive types such as T_INT.
aoqi@0 38
aoqi@0 39 // ------------------------------------------------------------------
aoqi@0 40 // ciType::ciType
aoqi@0 41 //
aoqi@0 42 ciType::ciType(BasicType basic_type) : ciMetadata() {
aoqi@0 43 assert(basic_type >= T_BOOLEAN && basic_type <= T_CONFLICT, "range check");
aoqi@0 44 _basic_type = basic_type;
aoqi@0 45 }
aoqi@0 46
aoqi@0 47 ciType::ciType(KlassHandle k) : ciMetadata(k()) {
aoqi@0 48 _basic_type = k()->oop_is_array() ? T_ARRAY : T_OBJECT;
aoqi@0 49 }
aoqi@0 50
aoqi@0 51
aoqi@0 52 // ------------------------------------------------------------------
aoqi@0 53 // ciType::is_subtype_of
aoqi@0 54 //
aoqi@0 55 bool ciType::is_subtype_of(ciType* type) {
aoqi@0 56 if (this == type) return true;
aoqi@0 57 if (is_klass() && type->is_klass())
aoqi@0 58 return this->as_klass()->is_subtype_of(type->as_klass());
aoqi@0 59 return false;
aoqi@0 60 }
aoqi@0 61
aoqi@0 62 // ------------------------------------------------------------------
aoqi@0 63 // ciType::name
aoqi@0 64 //
aoqi@0 65 // Return the name of this type
aoqi@0 66 const char* ciType::name() {
aoqi@0 67 if (is_primitive_type()) {
aoqi@0 68 return type2name(basic_type());
aoqi@0 69 } else {
aoqi@0 70 assert(is_klass(), "must be");
aoqi@0 71 return as_klass()->name()->as_utf8();
aoqi@0 72 }
aoqi@0 73 }
aoqi@0 74
aoqi@0 75 // ------------------------------------------------------------------
aoqi@0 76 // ciType::print_impl
aoqi@0 77 //
aoqi@0 78 // Implementation of the print method.
aoqi@0 79 void ciType::print_impl(outputStream* st) {
aoqi@0 80 st->print(" type=");
aoqi@0 81 print_name_on(st);
aoqi@0 82 }
aoqi@0 83
aoqi@0 84 // ------------------------------------------------------------------
aoqi@0 85 // ciType::print_name
aoqi@0 86 //
aoqi@0 87 // Print the name of this type
aoqi@0 88 void ciType::print_name_on(outputStream* st) {
aoqi@0 89 ResourceMark rm;
aoqi@0 90 st->print("%s", name());
aoqi@0 91 }
aoqi@0 92
aoqi@0 93
aoqi@0 94
aoqi@0 95 // ------------------------------------------------------------------
aoqi@0 96 // ciType::java_mirror
aoqi@0 97 //
aoqi@0 98 ciInstance* ciType::java_mirror() {
aoqi@0 99 VM_ENTRY_MARK;
aoqi@0 100 return CURRENT_THREAD_ENV->get_instance(Universe::java_mirror(basic_type()));
aoqi@0 101 }
aoqi@0 102
aoqi@0 103 // ------------------------------------------------------------------
aoqi@0 104 // ciType::box_klass
aoqi@0 105 //
aoqi@0 106 ciKlass* ciType::box_klass() {
aoqi@0 107 if (!is_primitive_type()) return this->as_klass(); // reference types are "self boxing"
aoqi@0 108
aoqi@0 109 // Void is "boxed" with a null.
aoqi@0 110 if (basic_type() == T_VOID) return NULL;
aoqi@0 111
aoqi@0 112 VM_ENTRY_MARK;
aoqi@0 113 return CURRENT_THREAD_ENV->get_instance_klass(SystemDictionary::box_klass(basic_type()));
aoqi@0 114 }
aoqi@0 115
aoqi@0 116
aoqi@0 117 // ------------------------------------------------------------------
aoqi@0 118 // ciType::make
aoqi@0 119 //
aoqi@0 120 // Produce the ciType for a given primitive BasicType.
aoqi@0 121 // As a bonus, produce the right reference type for T_OBJECT.
aoqi@0 122 // Does not work on T_ARRAY.
aoqi@0 123 ciType* ciType::make(BasicType t) {
aoqi@0 124 // short, etc.
aoqi@0 125 // Note: Bare T_ADDRESS means a raw pointer type, not a return_address.
aoqi@0 126 assert((uint)t < T_CONFLICT+1, "range check");
aoqi@0 127 if (t == T_OBJECT) return ciEnv::_Object_klass; // java/lang/Object
aoqi@0 128 assert(_basic_types[t] != NULL, "domain check");
aoqi@0 129 return _basic_types[t];
aoqi@0 130 }
aoqi@0 131
aoqi@0 132 // ciReturnAddress
aoqi@0 133 //
aoqi@0 134 // This class represents the type of a specific return address in the
aoqi@0 135 // bytecodes.
aoqi@0 136
aoqi@0 137 // ------------------------------------------------------------------
aoqi@0 138 // ciReturnAddress::ciReturnAddress
aoqi@0 139 //
aoqi@0 140 ciReturnAddress::ciReturnAddress(int bci) : ciType(T_ADDRESS) {
aoqi@0 141 assert(0 <= bci, "bci cannot be negative");
aoqi@0 142 _bci = bci;
aoqi@0 143 }
aoqi@0 144
aoqi@0 145 // ------------------------------------------------------------------
aoqi@0 146 // ciReturnAddress::print_impl
aoqi@0 147 //
aoqi@0 148 // Implementation of the print method.
aoqi@0 149 void ciReturnAddress::print_impl(outputStream* st) {
aoqi@0 150 st->print(" bci=%d", _bci);
aoqi@0 151 }
aoqi@0 152
aoqi@0 153 // ------------------------------------------------------------------
aoqi@0 154 // ciReturnAddress::make
aoqi@0 155 ciReturnAddress* ciReturnAddress::make(int bci) {
aoqi@0 156 GUARDED_VM_ENTRY(return CURRENT_ENV->get_return_address(bci);)
aoqi@0 157 }

mercurial