1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/ci/ciType.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,157 @@ 1.4 +/* 1.5 + * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "ci/ciEnv.hpp" 1.30 +#include "ci/ciType.hpp" 1.31 +#include "ci/ciUtilities.hpp" 1.32 +#include "classfile/systemDictionary.hpp" 1.33 +#include "oops/oop.inline.hpp" 1.34 + 1.35 +ciType* ciType::_basic_types[T_CONFLICT+1]; 1.36 + 1.37 +// ciType 1.38 +// 1.39 +// This class represents either a class (T_OBJECT), array (T_ARRAY), 1.40 +// or one of the primitive types such as T_INT. 1.41 + 1.42 +// ------------------------------------------------------------------ 1.43 +// ciType::ciType 1.44 +// 1.45 +ciType::ciType(BasicType basic_type) : ciMetadata() { 1.46 + assert(basic_type >= T_BOOLEAN && basic_type <= T_CONFLICT, "range check"); 1.47 + _basic_type = basic_type; 1.48 +} 1.49 + 1.50 +ciType::ciType(KlassHandle k) : ciMetadata(k()) { 1.51 + _basic_type = k()->oop_is_array() ? T_ARRAY : T_OBJECT; 1.52 +} 1.53 + 1.54 + 1.55 +// ------------------------------------------------------------------ 1.56 +// ciType::is_subtype_of 1.57 +// 1.58 +bool ciType::is_subtype_of(ciType* type) { 1.59 + if (this == type) return true; 1.60 + if (is_klass() && type->is_klass()) 1.61 + return this->as_klass()->is_subtype_of(type->as_klass()); 1.62 + return false; 1.63 +} 1.64 + 1.65 +// ------------------------------------------------------------------ 1.66 +// ciType::name 1.67 +// 1.68 +// Return the name of this type 1.69 +const char* ciType::name() { 1.70 + if (is_primitive_type()) { 1.71 + return type2name(basic_type()); 1.72 + } else { 1.73 + assert(is_klass(), "must be"); 1.74 + return as_klass()->name()->as_utf8(); 1.75 + } 1.76 +} 1.77 + 1.78 +// ------------------------------------------------------------------ 1.79 +// ciType::print_impl 1.80 +// 1.81 +// Implementation of the print method. 1.82 +void ciType::print_impl(outputStream* st) { 1.83 + st->print(" type="); 1.84 + print_name_on(st); 1.85 +} 1.86 + 1.87 +// ------------------------------------------------------------------ 1.88 +// ciType::print_name 1.89 +// 1.90 +// Print the name of this type 1.91 +void ciType::print_name_on(outputStream* st) { 1.92 + ResourceMark rm; 1.93 + st->print("%s", name()); 1.94 +} 1.95 + 1.96 + 1.97 + 1.98 +// ------------------------------------------------------------------ 1.99 +// ciType::java_mirror 1.100 +// 1.101 +ciInstance* ciType::java_mirror() { 1.102 + VM_ENTRY_MARK; 1.103 + return CURRENT_THREAD_ENV->get_instance(Universe::java_mirror(basic_type())); 1.104 +} 1.105 + 1.106 +// ------------------------------------------------------------------ 1.107 +// ciType::box_klass 1.108 +// 1.109 +ciKlass* ciType::box_klass() { 1.110 + if (!is_primitive_type()) return this->as_klass(); // reference types are "self boxing" 1.111 + 1.112 + // Void is "boxed" with a null. 1.113 + if (basic_type() == T_VOID) return NULL; 1.114 + 1.115 + VM_ENTRY_MARK; 1.116 + return CURRENT_THREAD_ENV->get_instance_klass(SystemDictionary::box_klass(basic_type())); 1.117 +} 1.118 + 1.119 + 1.120 +// ------------------------------------------------------------------ 1.121 +// ciType::make 1.122 +// 1.123 +// Produce the ciType for a given primitive BasicType. 1.124 +// As a bonus, produce the right reference type for T_OBJECT. 1.125 +// Does not work on T_ARRAY. 1.126 +ciType* ciType::make(BasicType t) { 1.127 + // short, etc. 1.128 + // Note: Bare T_ADDRESS means a raw pointer type, not a return_address. 1.129 + assert((uint)t < T_CONFLICT+1, "range check"); 1.130 + if (t == T_OBJECT) return ciEnv::_Object_klass; // java/lang/Object 1.131 + assert(_basic_types[t] != NULL, "domain check"); 1.132 + return _basic_types[t]; 1.133 +} 1.134 + 1.135 +// ciReturnAddress 1.136 +// 1.137 +// This class represents the type of a specific return address in the 1.138 +// bytecodes. 1.139 + 1.140 +// ------------------------------------------------------------------ 1.141 +// ciReturnAddress::ciReturnAddress 1.142 +// 1.143 +ciReturnAddress::ciReturnAddress(int bci) : ciType(T_ADDRESS) { 1.144 + assert(0 <= bci, "bci cannot be negative"); 1.145 + _bci = bci; 1.146 +} 1.147 + 1.148 +// ------------------------------------------------------------------ 1.149 +// ciReturnAddress::print_impl 1.150 +// 1.151 +// Implementation of the print method. 1.152 +void ciReturnAddress::print_impl(outputStream* st) { 1.153 + st->print(" bci=%d", _bci); 1.154 +} 1.155 + 1.156 +// ------------------------------------------------------------------ 1.157 +// ciReturnAddress::make 1.158 +ciReturnAddress* ciReturnAddress::make(int bci) { 1.159 + GUARDED_VM_ENTRY(return CURRENT_ENV->get_return_address(bci);) 1.160 +}