src/share/vm/oops/constantPool.hpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2014, 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  *


  56   bool is_resolved()   { return (_ptr & 1) == 0; }
  57   bool is_unresolved() { return (_ptr & 1) == 1; }
  58 
  59   Symbol* get_symbol() {
  60     assert(is_unresolved(), "bad call");
  61     return (Symbol*)(_ptr & ~1);
  62   }
  63   Klass* get_klass() {
  64     assert(is_resolved(), "bad call");
  65     return (Klass*)_ptr;
  66   }
  67 };
  68 
  69 class KlassSizeStats;
  70 
  71 class ConstantPool : public Metadata {
  72   friend class VMStructs;
  73   friend class BytecodeInterpreter;  // Directly extracts a klass in the pool for fast instanceof/checkcast
  74   friend class Universe;             // For null constructor
  75  private:



  76   Array<u1>*           _tags;        // the tag array describing the constant pool's contents
  77   ConstantPoolCache*   _cache;       // the cache holding interpreter runtime information
  78   InstanceKlass*       _pool_holder; // the corresponding class
  79   Array<u2>*           _operands;    // for variable-sized (InvokeDynamic) nodes, usually empty
  80 
  81   // Array of resolved objects from the constant pool and map from resolved
  82   // object index to original constant pool index
  83   jobject              _resolved_references;
  84   Array<u2>*           _reference_map;
  85 
  86   enum {
  87     _has_preresolution = 1,           // Flags
  88     _on_stack          = 2
  89   };
  90 
  91   int                  _flags;  // old fashioned bit twiddling
  92   int                  _length; // number of elements in the array
  93 
  94   union {
  95     // set for CDS to restore resolved references


 388   oop string_at(int which, int obj_index, TRAPS) {
 389     constantPoolHandle h_this(THREAD, this);
 390     return string_at_impl(h_this, which, obj_index, THREAD);
 391   }
 392   oop string_at(int which, TRAPS) {
 393     int obj_index = cp_to_object_index(which);
 394     return string_at(which, obj_index, THREAD);
 395   }
 396 
 397   // Version that can be used before string oop array is created.
 398   oop uncached_string_at(int which, TRAPS);
 399 
 400   // A "pseudo-string" is an non-string oop that has found its way into
 401   // a String entry.
 402   // This can happen if the user patches a live
 403   // object into a CONSTANT_String entry of an anonymous class.
 404   // Method oops internally created for method handles may also
 405   // use pseudo-strings to link themselves to related metaobjects.
 406 
 407   bool is_pseudo_string_at(int which) {
 408     // A pseudo string is a string that doesn't have a symbol in the cpSlot
 409     return unresolved_string_at(which) == NULL;
 410   }
 411 
 412   oop pseudo_string_at(int which, int obj_index) {
 413     assert(tag_at(which).is_string(), "Corrupted constant pool");
 414     assert(unresolved_string_at(which) == NULL, "shouldn't have symbol");
 415     oop s = resolved_references()->obj_at(obj_index);
 416     return s;
 417   }
 418 
 419   oop pseudo_string_at(int which) {
 420     assert(tag_at(which).is_string(), "Corrupted constant pool");
 421     assert(unresolved_string_at(which) == NULL, "shouldn't have symbol");
 422     int obj_index = cp_to_object_index(which);
 423     oop s = resolved_references()->obj_at(obj_index);
 424     return s;
 425   }
 426 
 427   void pseudo_string_at_put(int which, int obj_index, oop x) {
 428     assert(tag_at(which).is_string(), "Corrupted constant pool");
 429     unresolved_string_at_put(which, NULL); // indicates patched string
 430     string_at_put(which, obj_index, x);    // this works just fine
 431   }
 432 
 433   // only called when we are sure a string entry is already resolved (via an
 434   // earlier string_at call.
 435   oop resolved_string_at(int which) {
 436     assert(tag_at(which).is_string(), "Corrupted constant pool");
 437     // Must do an acquire here in case another thread resolved the klass
 438     // behind our back, lest we later load stale values thru the oop.
 439     // we might want a volatile_obj_at in ObjArrayKlass.
 440     int obj_index = cp_to_object_index(which);
 441     return resolved_references()->obj_at(obj_index);
 442   }
 443 
 444   Symbol* unresolved_string_at(int which) {
 445     assert(tag_at(which).is_string(), "Corrupted constant pool");
 446     Symbol* s = *symbol_at_addr(which);
 447     return s;
 448   }
 449 


   1 /*
   2  * Copyright (c) 1997, 2015, 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  *


  56   bool is_resolved()   { return (_ptr & 1) == 0; }
  57   bool is_unresolved() { return (_ptr & 1) == 1; }
  58 
  59   Symbol* get_symbol() {
  60     assert(is_unresolved(), "bad call");
  61     return (Symbol*)(_ptr & ~1);
  62   }
  63   Klass* get_klass() {
  64     assert(is_resolved(), "bad call");
  65     return (Klass*)_ptr;
  66   }
  67 };
  68 
  69 class KlassSizeStats;
  70 
  71 class ConstantPool : public Metadata {
  72   friend class VMStructs;
  73   friend class BytecodeInterpreter;  // Directly extracts a klass in the pool for fast instanceof/checkcast
  74   friend class Universe;             // For null constructor
  75  private:
  76   static const char* CPH_STR;
  77   static const int   CPH_LEN;
  78  private:
  79   Array<u1>*           _tags;        // the tag array describing the constant pool's contents
  80   ConstantPoolCache*   _cache;       // the cache holding interpreter runtime information
  81   InstanceKlass*       _pool_holder; // the corresponding class
  82   Array<u2>*           _operands;    // for variable-sized (InvokeDynamic) nodes, usually empty
  83 
  84   // Array of resolved objects from the constant pool and map from resolved
  85   // object index to original constant pool index
  86   jobject              _resolved_references;
  87   Array<u2>*           _reference_map;
  88 
  89   enum {
  90     _has_preresolution = 1,           // Flags
  91     _on_stack          = 2
  92   };
  93 
  94   int                  _flags;  // old fashioned bit twiddling
  95   int                  _length; // number of elements in the array
  96 
  97   union {
  98     // set for CDS to restore resolved references


 391   oop string_at(int which, int obj_index, TRAPS) {
 392     constantPoolHandle h_this(THREAD, this);
 393     return string_at_impl(h_this, which, obj_index, THREAD);
 394   }
 395   oop string_at(int which, TRAPS) {
 396     int obj_index = cp_to_object_index(which);
 397     return string_at(which, obj_index, THREAD);
 398   }
 399 
 400   // Version that can be used before string oop array is created.
 401   oop uncached_string_at(int which, TRAPS);
 402 
 403   // A "pseudo-string" is an non-string oop that has found its way into
 404   // a String entry.
 405   // This can happen if the user patches a live
 406   // object into a CONSTANT_String entry of an anonymous class.
 407   // Method oops internally created for method handles may also
 408   // use pseudo-strings to link themselves to related metaobjects.
 409 
 410   bool is_pseudo_string_at(int which) {
 411     char* utf8 = unresolved_string_at(which)->as_utf8();
 412     return strlen(utf8) > CPH_LEN && strncmp(utf8, CPH_STR, CPH_LEN) == 0;
 413   }
 414 
 415   oop pseudo_string_at(int which, int obj_index) {
 416     assert(tag_at(which).is_string(), "Corrupted constant pool");
 417     assert(is_pseudo_string_at(which), "must be a pseudo-string");
 418     oop s = resolved_references()->obj_at(obj_index);
 419     return s;
 420   }
 421 
 422   oop pseudo_string_at(int which) {
 423     assert(tag_at(which).is_string(), "Corrupted constant pool");
 424     assert(is_pseudo_string_at(which), "must be a pseudo-string");
 425     int obj_index = cp_to_object_index(which);
 426     oop s = resolved_references()->obj_at(obj_index);
 427     return s;
 428   }
 429 
 430   void pseudo_string_at_put(int which, int obj_index, oop x) {
 431     assert(tag_at(which).is_string(), "Corrupted constant pool");

 432     string_at_put(which, obj_index, x);    // this works just fine
 433   }
 434 
 435   // only called when we are sure a string entry is already resolved (via an
 436   // earlier string_at call.
 437   oop resolved_string_at(int which) {
 438     assert(tag_at(which).is_string(), "Corrupted constant pool");
 439     // Must do an acquire here in case another thread resolved the klass
 440     // behind our back, lest we later load stale values thru the oop.
 441     // we might want a volatile_obj_at in ObjArrayKlass.
 442     int obj_index = cp_to_object_index(which);
 443     return resolved_references()->obj_at(obj_index);
 444   }
 445 
 446   Symbol* unresolved_string_at(int which) {
 447     assert(tag_at(which).is_string(), "Corrupted constant pool");
 448     Symbol* s = *symbol_at_addr(which);
 449     return s;
 450   }
 451