< prev index next >

src/share/vm/classfile/javaClasses.cpp

Print this page




 152 int java_lang_String::hash_offset   = 0;
 153 int java_lang_String::coder_offset  = 0;
 154 
 155 bool java_lang_String::initialized  = false;
 156 
 157 bool java_lang_String::is_instance(oop obj) {
 158   return is_instance_inlined(obj);
 159 }
 160 
 161 void java_lang_String::compute_offsets() {
 162   assert(!initialized, "offsets should be initialized only once");
 163 
 164   Klass* k = SystemDictionary::String_klass();
 165   compute_offset(value_offset,           k, vmSymbols::value_name(),  vmSymbols::byte_array_signature());
 166   compute_offset(hash_offset,            k, vmSymbols::hash_name(),   vmSymbols::int_signature());
 167   compute_offset(coder_offset,           k, vmSymbols::coder_name(),  vmSymbols::byte_signature());
 168 
 169   initialized = true;
 170 }
 171 
 172 class CompactStringsFixup : public FieldClosure {
 173 private:
 174   bool _value;

 175 
 176 public:
 177   CompactStringsFixup(bool value) : _value(value) {}
 178 
 179   void do_field(fieldDescriptor* fd) {
 180     if (fd->name() == vmSymbols::compact_strings_name()) {
 181       oop mirror = fd->field_holder()->java_mirror();
 182       assert(fd->field_holder() == SystemDictionary::String_klass(), "Should be String");
 183       assert(mirror != NULL, "String must have mirror already");
 184       mirror->bool_field_put(fd->offset(), _value);
 185     }
 186   }
 187 };
 188 
 189 void java_lang_String::set_compact_strings(bool value) {
 190   CompactStringsFixup fix(value);





 191   InstanceKlass::cast(SystemDictionary::String_klass())->do_local_static_fields(&fix);
 192 }
 193 
 194 Handle java_lang_String::basic_create(int length, bool is_latin1, TRAPS) {
 195   assert(initialized, "Must be initialized");
 196   assert(CompactStrings || !is_latin1, "Must be UTF16 without CompactStrings");
 197 
 198   // Create the String object first, so there's a chance that the String
 199   // and the char array it points to end up in the same cache line.
 200   oop obj;
 201   obj = SystemDictionary::String_klass()->allocate_instance(CHECK_NH);
 202 
 203   // Create the char array.  The String object must be handlized here
 204   // because GC can happen as a result of the allocation attempt.
 205   Handle h_obj(THREAD, obj);
 206   int arr_length = is_latin1 ? length : length << 1; // 2 bytes per UTF16.
 207   typeArrayOop buffer = oopFactory::new_byteArray(arr_length, CHECK_NH);;
 208 
 209   // Point the String at the char array
 210   obj = h_obj();




 152 int java_lang_String::hash_offset   = 0;
 153 int java_lang_String::coder_offset  = 0;
 154 
 155 bool java_lang_String::initialized  = false;
 156 
 157 bool java_lang_String::is_instance(oop obj) {
 158   return is_instance_inlined(obj);
 159 }
 160 
 161 void java_lang_String::compute_offsets() {
 162   assert(!initialized, "offsets should be initialized only once");
 163 
 164   Klass* k = SystemDictionary::String_klass();
 165   compute_offset(value_offset,           k, vmSymbols::value_name(),  vmSymbols::byte_array_signature());
 166   compute_offset(hash_offset,            k, vmSymbols::hash_name(),   vmSymbols::int_signature());
 167   compute_offset(coder_offset,           k, vmSymbols::coder_name(),  vmSymbols::byte_signature());
 168 
 169   initialized = true;
 170 }
 171 
 172 class StringBoolFieldFixup : public FieldClosure {
 173 private:
 174   bool _value;
 175   Symbol *_name;
 176 
 177 public:
 178   StringBoolFieldFixup(Symbol *name, bool value) : _name(name), _value(value) {}
 179 
 180   void do_field(fieldDescriptor* fd) {
 181     if (fd->name() == _name) {
 182       oop mirror = fd->field_holder()->java_mirror();
 183       assert(fd->field_holder() == SystemDictionary::String_klass(), "Should be String");
 184       assert(mirror != NULL, "String must have mirror already");
 185       mirror->bool_field_put(fd->offset(), _value);
 186     }
 187   }
 188 };
 189 
 190 void java_lang_String::set_compact_strings(bool value) {
 191   StringBoolFieldFixup fix(vmSymbols::compact_strings_name(), value);
 192   InstanceKlass::cast(SystemDictionary::String_klass())->do_local_static_fields(&fix);
 193 }
 194 
 195 void java_lang_String::set_debug_intrinsics(bool value) {
 196   StringBoolFieldFixup fix(vmSymbols::debug_intrinsics_name(), value);
 197   InstanceKlass::cast(SystemDictionary::String_klass())->do_local_static_fields(&fix);
 198 }
 199 
 200 Handle java_lang_String::basic_create(int length, bool is_latin1, TRAPS) {
 201   assert(initialized, "Must be initialized");
 202   assert(CompactStrings || !is_latin1, "Must be UTF16 without CompactStrings");
 203 
 204   // Create the String object first, so there's a chance that the String
 205   // and the char array it points to end up in the same cache line.
 206   oop obj;
 207   obj = SystemDictionary::String_klass()->allocate_instance(CHECK_NH);
 208 
 209   // Create the char array.  The String object must be handlized here
 210   // because GC can happen as a result of the allocation attempt.
 211   Handle h_obj(THREAD, obj);
 212   int arr_length = is_latin1 ? length : length << 1; // 2 bytes per UTF16.
 213   typeArrayOop buffer = oopFactory::new_byteArray(arr_length, CHECK_NH);;
 214 
 215   // Point the String at the char array
 216   obj = h_obj();


< prev index next >