src/share/vm/classfile/javaClasses.hpp

Print this page
rev 6083 : 8029075: String deduplication in G1
Implementation of JEP 192, http://openjdk.java.net/jeps/192
   1 /*
   2  * Copyright (c) 1997, 2013, 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  *


  44 // on a per class basis. The offsets below have to reflect this ordering.
  45 //
  46 // When editing the layouts please update the check_offset verification code
  47 // correspondingly. The names in the enums must be identical to the actual field
  48 // names in order for the verification code to work.
  49 
  50 
  51 // Interface to java.lang.String objects
  52 
  53 class java_lang_String : AllStatic {
  54  private:
  55   static int value_offset;
  56   static int offset_offset;
  57   static int count_offset;
  58   static int hash_offset;
  59 
  60   static bool initialized;
  61 
  62   static Handle basic_create(int length, TRAPS);
  63 
  64   static void set_value( oop string, typeArrayOop buffer) {
  65     assert(initialized, "Must be initialized");
  66     string->obj_field_put(value_offset,  (oop)buffer);
  67   }
  68   static void set_offset(oop string, int offset) {
  69     assert(initialized, "Must be initialized");
  70     if (offset_offset > 0) {
  71       string->int_field_put(offset_offset, offset);
  72     }
  73   }
  74   static void set_count( oop string, int count) {
  75     assert(initialized, "Must be initialized");
  76     if (count_offset > 0) {
  77       string->int_field_put(count_offset,  count);
  78     }
  79   }
  80 
  81  public:
  82   static void compute_offsets();
  83 
  84   // Instance creation
  85   static Handle create_from_unicode(jchar* unicode, int len, TRAPS);
  86   static oop    create_oop_from_unicode(jchar* unicode, int len, TRAPS);
  87   static Handle create_from_str(const char* utf8_str, TRAPS);


 105     return (hash_offset > 0);
 106   }
 107 
 108   static int value_offset_in_bytes()  {
 109     assert(initialized && (value_offset > 0), "Must be initialized");
 110     return value_offset;
 111   }
 112   static int count_offset_in_bytes()  {
 113     assert(initialized && (count_offset > 0), "Must be initialized");
 114     return count_offset;
 115   }
 116   static int offset_offset_in_bytes() {
 117     assert(initialized && (offset_offset > 0), "Must be initialized");
 118     return offset_offset;
 119   }
 120   static int hash_offset_in_bytes()   {
 121     assert(initialized && (hash_offset > 0), "Must be initialized");
 122     return hash_offset;
 123   }
 124 









 125   // Accessors
 126   static typeArrayOop value(oop java_string) {
 127     assert(initialized && (value_offset > 0), "Must be initialized");
 128     assert(is_instance(java_string), "must be java_string");
 129     return (typeArrayOop) java_string->obj_field(value_offset);
 130   }





 131   static int offset(oop java_string) {
 132     assert(initialized, "Must be initialized");
 133     assert(is_instance(java_string), "must be java_string");
 134     if (offset_offset > 0) {
 135       return java_string->int_field(offset_offset);
 136     } else {
 137       return 0;
 138     }
 139   }
 140   static int length(oop java_string) {
 141     assert(initialized, "Must be initialized");
 142     assert(is_instance(java_string), "must be java_string");
 143     if (count_offset > 0) {
 144       return java_string->int_field(count_offset);
 145     } else {
 146       return ((typeArrayOop)java_string->obj_field(value_offset))->length();
 147     }
 148   }
 149   static int utf8_length(oop java_string);
 150 


   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  *


  44 // on a per class basis. The offsets below have to reflect this ordering.
  45 //
  46 // When editing the layouts please update the check_offset verification code
  47 // correspondingly. The names in the enums must be identical to the actual field
  48 // names in order for the verification code to work.
  49 
  50 
  51 // Interface to java.lang.String objects
  52 
  53 class java_lang_String : AllStatic {
  54  private:
  55   static int value_offset;
  56   static int offset_offset;
  57   static int count_offset;
  58   static int hash_offset;
  59 
  60   static bool initialized;
  61 
  62   static Handle basic_create(int length, TRAPS);
  63 




  64   static void set_offset(oop string, int offset) {
  65     assert(initialized, "Must be initialized");
  66     if (offset_offset > 0) {
  67       string->int_field_put(offset_offset, offset);
  68     }
  69   }
  70   static void set_count( oop string, int count) {
  71     assert(initialized, "Must be initialized");
  72     if (count_offset > 0) {
  73       string->int_field_put(count_offset,  count);
  74     }
  75   }
  76 
  77  public:
  78   static void compute_offsets();
  79 
  80   // Instance creation
  81   static Handle create_from_unicode(jchar* unicode, int len, TRAPS);
  82   static oop    create_oop_from_unicode(jchar* unicode, int len, TRAPS);
  83   static Handle create_from_str(const char* utf8_str, TRAPS);


 101     return (hash_offset > 0);
 102   }
 103 
 104   static int value_offset_in_bytes()  {
 105     assert(initialized && (value_offset > 0), "Must be initialized");
 106     return value_offset;
 107   }
 108   static int count_offset_in_bytes()  {
 109     assert(initialized && (count_offset > 0), "Must be initialized");
 110     return count_offset;
 111   }
 112   static int offset_offset_in_bytes() {
 113     assert(initialized && (offset_offset > 0), "Must be initialized");
 114     return offset_offset;
 115   }
 116   static int hash_offset_in_bytes()   {
 117     assert(initialized && (hash_offset > 0), "Must be initialized");
 118     return hash_offset;
 119   }
 120 
 121   static void set_value(oop string, typeArrayOop buffer) {
 122     assert(initialized && (value_offset > 0), "Must be initialized");
 123     string->obj_field_put(value_offset, (oop)buffer);
 124   }
 125   static void set_hash(oop string, unsigned int hash) {
 126     assert(initialized && (hash_offset > 0), "Must be initialized");
 127     string->int_field_put(hash_offset, hash);
 128   }
 129 
 130   // Accessors
 131   static typeArrayOop value(oop java_string) {
 132     assert(initialized && (value_offset > 0), "Must be initialized");
 133     assert(is_instance(java_string), "must be java_string");
 134     return (typeArrayOop) java_string->obj_field(value_offset);
 135   }
 136   static unsigned int hash(oop java_string) {
 137     assert(initialized && (hash_offset > 0), "Must be initialized");
 138     assert(is_instance(java_string), "must be java_string");
 139     return java_string->int_field(hash_offset);
 140   }
 141   static int offset(oop java_string) {
 142     assert(initialized, "Must be initialized");
 143     assert(is_instance(java_string), "must be java_string");
 144     if (offset_offset > 0) {
 145       return java_string->int_field(offset_offset);
 146     } else {
 147       return 0;
 148     }
 149   }
 150   static int length(oop java_string) {
 151     assert(initialized, "Must be initialized");
 152     assert(is_instance(java_string), "must be java_string");
 153     if (count_offset > 0) {
 154       return java_string->int_field(count_offset);
 155     } else {
 156       return ((typeArrayOop)java_string->obj_field(value_offset))->length();
 157     }
 158   }
 159   static int utf8_length(oop java_string);
 160