src/share/vm/ci/ciType.cpp

changeset 435
a61af66fc99e
child 1577
4ce7240d622c
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/ci/ciType.cpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,144 @@
     1.4 +/*
     1.5 + * Copyright 2000-2002 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "incls/_precompiled.incl"
    1.29 +#include "incls/_ciType.cpp.incl"
    1.30 +
    1.31 +ciType* ciType::_basic_types[T_CONFLICT+1];
    1.32 +
    1.33 +// ciType
    1.34 +//
    1.35 +// This class represents either a class (T_OBJECT), array (T_ARRAY),
    1.36 +// or one of the primitive types such as T_INT.
    1.37 +
    1.38 +// ------------------------------------------------------------------
    1.39 +// ciType::ciType
    1.40 +//
    1.41 +ciType::ciType(BasicType basic_type) : ciObject() {
    1.42 +  assert(basic_type >= T_BOOLEAN && basic_type <= T_CONFLICT, "range check");
    1.43 +  assert(basic_type != T_OBJECT && basic_type != T_ARRAY, "not a reference type");
    1.44 +  _basic_type = basic_type;
    1.45 +}
    1.46 +
    1.47 +ciType::ciType(KlassHandle k) : ciObject(k) {
    1.48 +  _basic_type = Klass::cast(k())->oop_is_array() ? T_ARRAY : T_OBJECT;
    1.49 +}
    1.50 +
    1.51 +ciType::ciType(ciKlass* klass) : ciObject(klass) {
    1.52 +  _basic_type = klass->is_array_klass_klass() ? T_ARRAY : T_OBJECT;
    1.53 +}
    1.54 +
    1.55 +
    1.56 +// ------------------------------------------------------------------
    1.57 +// ciType::is_subtype_of
    1.58 +//
    1.59 +bool ciType::is_subtype_of(ciType* type) {
    1.60 +  if (this == type)  return true;
    1.61 +  if (is_klass() && type->is_klass())
    1.62 +    return this->as_klass()->is_subtype_of(type->as_klass());
    1.63 +  return false;
    1.64 +}
    1.65 +
    1.66 +// ------------------------------------------------------------------
    1.67 +// ciType::print_impl
    1.68 +//
    1.69 +// Implementation of the print method.
    1.70 +void ciType::print_impl(outputStream* st) {
    1.71 +  st->print(" type=");
    1.72 +  print_name_on(st);
    1.73 +}
    1.74 +
    1.75 +// ------------------------------------------------------------------
    1.76 +// ciType::print_name
    1.77 +//
    1.78 +// Print the name of this type
    1.79 +void ciType::print_name_on(outputStream* st) {
    1.80 +  st->print(type2name(basic_type()));
    1.81 +}
    1.82 +
    1.83 +
    1.84 +
    1.85 +// ------------------------------------------------------------------
    1.86 +// ciType::java_mirror
    1.87 +//
    1.88 +ciInstance* ciType::java_mirror() {
    1.89 +  VM_ENTRY_MARK;
    1.90 +  return CURRENT_THREAD_ENV->get_object(Universe::java_mirror(basic_type()))->as_instance();
    1.91 +}
    1.92 +
    1.93 +// ------------------------------------------------------------------
    1.94 +// ciType::box_klass
    1.95 +//
    1.96 +ciKlass* ciType::box_klass() {
    1.97 +  if (!is_primitive_type())  return this->as_klass();  // reference types are "self boxing"
    1.98 +
    1.99 +  // Void is "boxed" with a null.
   1.100 +  if (basic_type() == T_VOID)  return NULL;
   1.101 +
   1.102 +  VM_ENTRY_MARK;
   1.103 +  return CURRENT_THREAD_ENV->get_object(SystemDictionary::box_klass(basic_type()))->as_instance_klass();
   1.104 +}
   1.105 +
   1.106 +
   1.107 +// ------------------------------------------------------------------
   1.108 +// ciType::make
   1.109 +//
   1.110 +// Produce the ciType for a given primitive BasicType.
   1.111 +// As a bonus, produce the right reference type for T_OBJECT.
   1.112 +// Does not work on T_ARRAY.
   1.113 +ciType* ciType::make(BasicType t) {
   1.114 +  // short, etc.
   1.115 +  // Note: Bare T_ADDRESS means a raw pointer type, not a return_address.
   1.116 +  assert((uint)t < T_CONFLICT+1, "range check");
   1.117 +  if (t == T_OBJECT)  return ciEnv::_Object;  // java/lang/Object
   1.118 +  assert(_basic_types[t] != NULL, "domain check");
   1.119 +  return _basic_types[t];
   1.120 +}
   1.121 +
   1.122 +// ciReturnAddress
   1.123 +//
   1.124 +// This class represents the type of a specific return address in the
   1.125 +// bytecodes.
   1.126 +
   1.127 +// ------------------------------------------------------------------
   1.128 +// ciReturnAddress::ciReturnAddress
   1.129 +//
   1.130 +ciReturnAddress::ciReturnAddress(int bci) : ciType(T_ADDRESS) {
   1.131 +  assert(0 <= bci, "bci cannot be negative");
   1.132 +  _bci = bci;
   1.133 +}
   1.134 +
   1.135 +// ------------------------------------------------------------------
   1.136 +// ciReturnAddress::print_impl
   1.137 +//
   1.138 +// Implementation of the print method.
   1.139 +void ciReturnAddress::print_impl(outputStream* st) {
   1.140 +  st->print(" bci=%d", _bci);
   1.141 +}
   1.142 +
   1.143 +// ------------------------------------------------------------------
   1.144 +// ciReturnAddress::make
   1.145 +ciReturnAddress* ciReturnAddress::make(int bci) {
   1.146 +  GUARDED_VM_ENTRY(return CURRENT_ENV->get_return_address(bci);)
   1.147 +}

mercurial