hotspot/src/share/vm/ci/ciObject.cpp
changeset 13728 882756847a04
parent 10514 e229a19078cf
child 24322 c2978d1578e3
equal deleted inserted replaced
13727:caf5eb7dd4a7 13728:882756847a04
     1 /*
     1 /*
     2  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    41 // GC and compilation can proceed independently without
    41 // GC and compilation can proceed independently without
    42 // interference.
    42 // interference.
    43 //
    43 //
    44 // Within the VM, the oop and klass hierarchies are separate.
    44 // Within the VM, the oop and klass hierarchies are separate.
    45 // The compiler interface does not preserve this separation --
    45 // The compiler interface does not preserve this separation --
    46 // the distinction between `klassOop' and `Klass' are not
    46 // the distinction between `Klass*' and `Klass' are not
    47 // reflected in the interface and instead the Klass hierarchy
    47 // reflected in the interface and instead the Klass hierarchy
    48 // is directly modeled as the subclasses of ciKlass.
    48 // is directly modeled as the subclasses of ciKlass.
    49 
    49 
    50 // ------------------------------------------------------------------
    50 // ------------------------------------------------------------------
    51 // ciObject::ciObject
    51 // ciObject::ciObject
    55     _handle = JNIHandles::make_local(o);
    55     _handle = JNIHandles::make_local(o);
    56   } else {
    56   } else {
    57     _handle = JNIHandles::make_global(o);
    57     _handle = JNIHandles::make_global(o);
    58   }
    58   }
    59   _klass = NULL;
    59   _klass = NULL;
    60   _ident = 0;
       
    61   init_flags_from(o);
    60   init_flags_from(o);
    62 }
    61 }
    63 
    62 
    64 // ------------------------------------------------------------------
    63 // ------------------------------------------------------------------
    65 // ciObject::ciObject
    64 // ciObject::ciObject
    70     _handle = JNIHandles::make_local(h());
    69     _handle = JNIHandles::make_local(h());
    71   } else {
    70   } else {
    72     _handle = JNIHandles::make_global(h);
    71     _handle = JNIHandles::make_global(h);
    73   }
    72   }
    74   _klass = NULL;
    73   _klass = NULL;
    75   _ident = 0;
       
    76   init_flags_from(h());
    74   init_flags_from(h());
    77 }
    75 }
    78 
    76 
    79 // ------------------------------------------------------------------
    77 // ------------------------------------------------------------------
    80 // ciObject::ciObject
    78 // ciObject::ciObject
    84 ciObject::ciObject(ciKlass* klass) {
    82 ciObject::ciObject(ciKlass* klass) {
    85   ASSERT_IN_VM;
    83   ASSERT_IN_VM;
    86   assert(klass != NULL, "must supply klass");
    84   assert(klass != NULL, "must supply klass");
    87   _handle = NULL;
    85   _handle = NULL;
    88   _klass = klass;
    86   _klass = klass;
    89   _ident = 0;
       
    90 }
    87 }
    91 
    88 
    92 // ------------------------------------------------------------------
    89 // ------------------------------------------------------------------
    93 // ciObject::ciObject
    90 // ciObject::ciObject
    94 //
    91 //
    95 // NULL variant.  Used only by ciNullObject.
    92 // NULL variant.  Used only by ciNullObject.
    96 ciObject::ciObject() {
    93 ciObject::ciObject() {
    97   ASSERT_IN_VM;
    94   ASSERT_IN_VM;
    98   _handle = NULL;
    95   _handle = NULL;
    99   _klass = NULL;
    96   _klass = NULL;
   100   _ident = 0;
       
   101 }
    97 }
   102 
    98 
   103 // ------------------------------------------------------------------
    99 // ------------------------------------------------------------------
   104 // ciObject::klass
   100 // ciObject::klass
   105 //
   101 //
   115       return NULL;
   111       return NULL;
   116     }
   112     }
   117 
   113 
   118     GUARDED_VM_ENTRY(
   114     GUARDED_VM_ENTRY(
   119       oop o = get_oop();
   115       oop o = get_oop();
   120       _klass = CURRENT_ENV->get_object(o->klass())->as_klass();
   116       _klass = CURRENT_ENV->get_klass(o->klass());
   121     );
   117     );
   122   }
   118   }
   123   return _klass;
   119   return _klass;
   124 }
       
   125 
       
   126 // ------------------------------------------------------------------
       
   127 // ciObject::set_ident
       
   128 //
       
   129 // Set the unique identity number of a ciObject.
       
   130 void ciObject::set_ident(uint id) {
       
   131   assert((_ident >> FLAG_BITS) == 0, "must only initialize once");
       
   132   assert( id < ((uint)1 << (BitsPerInt-FLAG_BITS)), "id too big");
       
   133   _ident = _ident + (id << FLAG_BITS);
       
   134 }
       
   135 
       
   136 // ------------------------------------------------------------------
       
   137 // ciObject::ident
       
   138 //
       
   139 // Report the unique identity number of a ciObject.
       
   140 uint ciObject::ident() {
       
   141   uint id = _ident >> FLAG_BITS;
       
   142   assert(id != 0, "must be initialized");
       
   143   return id;
       
   144 }
   120 }
   145 
   121 
   146 // ------------------------------------------------------------------
   122 // ------------------------------------------------------------------
   147 // ciObject::equals
   123 // ciObject::equals
   148 //
   124 //
   185 
   161 
   186 // ------------------------------------------------------------------
   162 // ------------------------------------------------------------------
   187 // ciObject::can_be_constant
   163 // ciObject::can_be_constant
   188 bool ciObject::can_be_constant() {
   164 bool ciObject::can_be_constant() {
   189   if (ScavengeRootsInCode >= 1)  return true;  // now everybody can encode as a constant
   165   if (ScavengeRootsInCode >= 1)  return true;  // now everybody can encode as a constant
   190   return handle() == NULL || is_perm();
   166   return handle() == NULL;
   191 }
   167 }
   192 
   168 
   193 // ------------------------------------------------------------------
   169 // ------------------------------------------------------------------
   194 // ciObject::should_be_constant()
   170 // ciObject::should_be_constant()
   195 bool ciObject::should_be_constant() {
   171 bool ciObject::should_be_constant() {
   196   if (ScavengeRootsInCode >= 2)  return true;  // force everybody to be a constant
   172   if (ScavengeRootsInCode >= 2)  return true;  // force everybody to be a constant
   197   if (is_null_object()) return true;
   173   if (is_null_object()) return true;
   198 
   174 
   199   ciEnv* env = CURRENT_ENV;
   175   ciEnv* env = CURRENT_ENV;
   200   if (!JavaObjectsInPerm) {
   176 
   201     // We want Strings and Classes to be embeddable by default since
   177     // We want Strings and Classes to be embeddable by default since
   202     // they used to be in the perm world.  Not all Strings used to be
   178     // they used to be in the perm world.  Not all Strings used to be
   203     // embeddable but there's no easy way to distinguish the interned
   179     // embeddable but there's no easy way to distinguish the interned
   204     // from the regulars ones so just treat them all that way.
   180     // from the regulars ones so just treat them all that way.
   205     if (klass() == env->String_klass() || klass() == env->Class_klass()) {
   181     if (klass() == env->String_klass() || klass() == env->Class_klass()) {
   206       return true;
   182       return true;
   207     }
   183     }
   208   }
       
   209   if (EnableInvokeDynamic &&
   184   if (EnableInvokeDynamic &&
   210       (klass()->is_subclass_of(env->MethodHandle_klass()) ||
   185       (klass()->is_subclass_of(env->MethodHandle_klass()) ||
   211        klass()->is_subclass_of(env->CallSite_klass()))) {
   186        klass()->is_subclass_of(env->CallSite_klass()))) {
   212     assert(ScavengeRootsInCode >= 1, "must be");
   187     assert(ScavengeRootsInCode >= 1, "must be");
   213     // We want to treat these aggressively.
   188     // We want to treat these aggressively.
   214     return true;
   189     return true;
   215   }
   190   }
   216 
   191 
   217   return handle() == NULL || is_perm();
   192   return handle() == NULL;
   218 }
   193 }
   219 
   194 
       
   195 // ------------------------------------------------------------------
       
   196 // ciObject::should_be_constant()
       
   197 void ciObject::init_flags_from(oop x) {
       
   198   int flags = 0;
       
   199   if (x != NULL) {
       
   200     assert(Universe::heap()->is_in_reserved(x), "must be");
       
   201     if (x->is_scavengable())
       
   202       flags |= SCAVENGABLE_FLAG;
       
   203   }
       
   204   _ident |= flags;
       
   205 }
   220 
   206 
   221 // ------------------------------------------------------------------
   207 // ------------------------------------------------------------------
   222 // ciObject::print
   208 // ciObject::print
   223 //
   209 //
   224 // Print debugging output about this ciObject.
   210 // Print debugging output about this ciObject.
   226 // Implementation note: dispatch to the virtual print_impl behavior
   212 // Implementation note: dispatch to the virtual print_impl behavior
   227 // for this ciObject.
   213 // for this ciObject.
   228 void ciObject::print(outputStream* st) {
   214 void ciObject::print(outputStream* st) {
   229   st->print("<%s", type_string());
   215   st->print("<%s", type_string());
   230   GUARDED_VM_ENTRY(print_impl(st);)
   216   GUARDED_VM_ENTRY(print_impl(st);)
   231   st->print(" ident=%d %s%s address=0x%x>", ident(),
   217   st->print(" ident=%d %s address=0x%x>", ident(),
   232         is_perm() ? "PERM" : "",
       
   233         is_scavengable() ? "SCAVENGABLE" : "",
   218         is_scavengable() ? "SCAVENGABLE" : "",
   234         (address)this);
   219         (address)this);
   235 }
   220 }
   236 
   221 
   237 // ------------------------------------------------------------------
   222 // ------------------------------------------------------------------