ciType.cpp revision 0:a61af66fc99e
1/*
2 * Copyright 2000-2002 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
24
25#include "incls/_precompiled.incl"
26#include "incls/_ciType.cpp.incl"
27
28ciType* ciType::_basic_types[T_CONFLICT+1];
29
30// ciType
31//
32// This class represents either a class (T_OBJECT), array (T_ARRAY),
33// or one of the primitive types such as T_INT.
34
35// ------------------------------------------------------------------
36// ciType::ciType
37//
38ciType::ciType(BasicType basic_type) : ciObject() {
39  assert(basic_type >= T_BOOLEAN && basic_type <= T_CONFLICT, "range check");
40  assert(basic_type != T_OBJECT && basic_type != T_ARRAY, "not a reference type");
41  _basic_type = basic_type;
42}
43
44ciType::ciType(KlassHandle k) : ciObject(k) {
45  _basic_type = Klass::cast(k())->oop_is_array() ? T_ARRAY : T_OBJECT;
46}
47
48ciType::ciType(ciKlass* klass) : ciObject(klass) {
49  _basic_type = klass->is_array_klass_klass() ? T_ARRAY : T_OBJECT;
50}
51
52
53// ------------------------------------------------------------------
54// ciType::is_subtype_of
55//
56bool ciType::is_subtype_of(ciType* type) {
57  if (this == type)  return true;
58  if (is_klass() && type->is_klass())
59    return this->as_klass()->is_subtype_of(type->as_klass());
60  return false;
61}
62
63// ------------------------------------------------------------------
64// ciType::print_impl
65//
66// Implementation of the print method.
67void ciType::print_impl(outputStream* st) {
68  st->print(" type=");
69  print_name_on(st);
70}
71
72// ------------------------------------------------------------------
73// ciType::print_name
74//
75// Print the name of this type
76void ciType::print_name_on(outputStream* st) {
77  st->print(type2name(basic_type()));
78}
79
80
81
82// ------------------------------------------------------------------
83// ciType::java_mirror
84//
85ciInstance* ciType::java_mirror() {
86  VM_ENTRY_MARK;
87  return CURRENT_THREAD_ENV->get_object(Universe::java_mirror(basic_type()))->as_instance();
88}
89
90// ------------------------------------------------------------------
91// ciType::box_klass
92//
93ciKlass* ciType::box_klass() {
94  if (!is_primitive_type())  return this->as_klass();  // reference types are "self boxing"
95
96  // Void is "boxed" with a null.
97  if (basic_type() == T_VOID)  return NULL;
98
99  VM_ENTRY_MARK;
100  return CURRENT_THREAD_ENV->get_object(SystemDictionary::box_klass(basic_type()))->as_instance_klass();
101}
102
103
104// ------------------------------------------------------------------
105// ciType::make
106//
107// Produce the ciType for a given primitive BasicType.
108// As a bonus, produce the right reference type for T_OBJECT.
109// Does not work on T_ARRAY.
110ciType* ciType::make(BasicType t) {
111  // short, etc.
112  // Note: Bare T_ADDRESS means a raw pointer type, not a return_address.
113  assert((uint)t < T_CONFLICT+1, "range check");
114  if (t == T_OBJECT)  return ciEnv::_Object;  // java/lang/Object
115  assert(_basic_types[t] != NULL, "domain check");
116  return _basic_types[t];
117}
118
119// ciReturnAddress
120//
121// This class represents the type of a specific return address in the
122// bytecodes.
123
124// ------------------------------------------------------------------
125// ciReturnAddress::ciReturnAddress
126//
127ciReturnAddress::ciReturnAddress(int bci) : ciType(T_ADDRESS) {
128  assert(0 <= bci, "bci cannot be negative");
129  _bci = bci;
130}
131
132// ------------------------------------------------------------------
133// ciReturnAddress::print_impl
134//
135// Implementation of the print method.
136void ciReturnAddress::print_impl(outputStream* st) {
137  st->print(" bci=%d", _bci);
138}
139
140// ------------------------------------------------------------------
141// ciReturnAddress::make
142ciReturnAddress* ciReturnAddress::make(int bci) {
143  GUARDED_VM_ENTRY(return CURRENT_ENV->get_return_address(bci);)
144}
145