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