src/share/vm/classfile/vmSymbols.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/classfile

src/share/vm/classfile/vmSymbols.cpp

Print this page




  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  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/vmSymbols.hpp"
  27 #include "memory/oopFactory.hpp"
  28 #include "oops/oop.inline.hpp"
  29 #include "runtime/handles.inline.hpp"
  30 #include "utilities/xmlstream.hpp"
  31 
  32 
  33 Symbol* vmSymbols::_symbols[vmSymbols::SID_LIMIT];
  34 
  35 Symbol* vmSymbols::_type_signatures[T_VOID+1] = { NULL /*, NULL...*/ };
  36 
  37 inline int compare_symbol(Symbol* a, Symbol* b) {
  38   if (a == b)  return 0;
  39   // follow the natural address order:
  40   return (address)a > (address)b ? +1 : -1;
  41 }
  42 
  43 static vmSymbols::SID vm_symbol_index[vmSymbols::SID_LIMIT];
  44 extern "C" {
  45   static int compare_vmsymbol_sid(const void* void_a, const void* void_b) {
  46     Symbol* a = vmSymbols::symbol_at(*((vmSymbols::SID*) void_a));
  47     Symbol* b = vmSymbols::symbol_at(*((vmSymbols::SID*) void_b));
  48     return compare_symbol(a, b);
  49   }
  50 }
  51 
  52 #ifdef ASSERT
  53 #define VM_SYMBOL_ENUM_NAME_BODY(name, string) #name "\0"
  54 static const char* vm_symbol_enum_names =
  55   VM_SYMBOLS_DO(VM_SYMBOL_ENUM_NAME_BODY, VM_ALIAS_IGNORE)
  56   "\0";
  57 static const char* vm_symbol_enum_name(vmSymbols::SID sid) {
  58   const char* string = &vm_symbol_enum_names[0];


  85       string += 1;              // skip trailing null
  86     }
  87 
  88     _type_signatures[T_BYTE]    = byte_signature();
  89     _type_signatures[T_CHAR]    = char_signature();
  90     _type_signatures[T_DOUBLE]  = double_signature();
  91     _type_signatures[T_FLOAT]   = float_signature();
  92     _type_signatures[T_INT]     = int_signature();
  93     _type_signatures[T_LONG]    = long_signature();
  94     _type_signatures[T_SHORT]   = short_signature();
  95     _type_signatures[T_BOOLEAN] = bool_signature();
  96     _type_signatures[T_VOID]    = void_signature();
  97     // no single signatures for T_OBJECT or T_ARRAY
  98   }
  99 
 100 #ifdef ASSERT
 101   // Check for duplicates:
 102   for (int i1 = (int)FIRST_SID; i1 < (int)SID_LIMIT; i1++) {
 103     Symbol* sym = symbol_at((SID)i1);
 104     for (int i2 = (int)FIRST_SID; i2 < i1; i2++) {
 105       if (symbol_at((SID)i2) == sym) {
 106         tty->print("*** Duplicate VM symbol SIDs %s(%d) and %s(%d): \"",
 107                    vm_symbol_enum_name((SID)i2), i2,
 108                    vm_symbol_enum_name((SID)i1), i1);
 109         sym->print_symbol_on(tty);
 110         tty->print_cr("\"");
 111       }
 112     }
 113   }
 114 #endif //ASSERT
 115 
 116   // Create an index for find_id:
 117   {
 118     for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
 119       vm_symbol_index[index] = (SID)index;
 120     }
 121     int num_sids = SID_LIMIT-FIRST_SID;
 122     qsort(&vm_symbol_index[FIRST_SID], num_sids, sizeof(vm_symbol_index[0]),
 123           compare_vmsymbol_sid);
 124   }
 125 


 174 
 175 void vmSymbols::symbols_do(SymbolClosure* f) {
 176   for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
 177     f->do_symbol(&_symbols[index]);
 178   }
 179   for (int i = 0; i < T_VOID+1; i++) {
 180     f->do_symbol(&_type_signatures[i]);
 181   }
 182 }
 183 
 184 void vmSymbols::serialize(SerializeClosure* soc) {
 185   soc->do_region((u_char*)&_symbols[FIRST_SID],
 186                  (SID_LIMIT - FIRST_SID) * sizeof(_symbols[0]));
 187   soc->do_region((u_char*)_type_signatures, sizeof(_type_signatures));
 188 }
 189 
 190 
 191 BasicType vmSymbols::signature_type(Symbol* s) {
 192   assert(s != NULL, "checking");
 193   for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
 194     if (s == _type_signatures[i]) {
 195       return (BasicType)i;
 196     }
 197   }
 198   return T_OBJECT;
 199 }
 200 
 201 
 202 static int mid_hint = (int)vmSymbols::FIRST_SID+1;
 203 
 204 #ifndef PRODUCT
 205 static int find_sid_calls, find_sid_probes;
 206 // (Typical counts are calls=7000 and probes=17000.)
 207 #endif
 208 
 209 vmSymbols::SID vmSymbols::find_sid(Symbol* symbol) {
 210   // Handle the majority of misses by a bounds check.
 211   // Then, use a binary search over the index.
 212   // Expected trip count is less than log2_SID_LIMIT, about eight.
 213   // This is slow but acceptable, given that calls are not
 214   // dynamically common.  (Method*::intrinsic_id has a cache.)


 245           min = mid + 1;
 246 
 247         // Pick a new probe point:
 248         mid = (max + min) / 2;
 249       }
 250     }
 251   }
 252 
 253 #ifdef ASSERT
 254   // Perform the exhaustive self-check the first 1000 calls,
 255   // and every 100 calls thereafter.
 256   static int find_sid_check_count = -2000;
 257   if ((uint)++find_sid_check_count > (uint)100) {
 258     if (find_sid_check_count > 0)  find_sid_check_count = 0;
 259 
 260     // Make sure this is the right answer, using linear search.
 261     // (We have already proven that there are no duplicates in the list.)
 262     SID sid2 = NO_SID;
 263     for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
 264       Symbol* sym2 = symbol_at((SID)index);
 265       if (sym2 == symbol) {
 266         sid2 = (SID)index;
 267         break;
 268       }
 269     }
 270     // Unless it's a duplicate, assert that the sids are the same.
 271     if (_symbols[sid] != _symbols[sid2]) {
 272       assert(sid == sid2, "binary same as linear search");
 273     }
 274   }
 275 #endif //ASSERT
 276 
 277   return sid;
 278 }
 279 
 280 vmSymbols::SID vmSymbols::find_sid(const char* symbol_name) {
 281   Symbol* symbol = SymbolTable::probe(symbol_name, (int) strlen(symbol_name));
 282   if (symbol == NULL)  return NO_SID;
 283   return find_sid(symbol);
 284 }
 285 
 286 static vmIntrinsics::ID wrapper_intrinsic(BasicType type, bool unboxing) {
 287 #define TYPE2(type, unboxing) ((int)(type)*2 + ((unboxing) ? 1 : 0))
 288   switch (TYPE2(type, unboxing)) {
 289 #define BASIC_TYPE_CASE(type, box, unbox) \
 290     case TYPE2(type, false):  return vmIntrinsics::box; \
 291     case TYPE2(type, true):   return vmIntrinsics::unbox


 470 
 471 vmSymbols::SID vmIntrinsics::signature_for(vmIntrinsics::ID id) {
 472   jlong info = intrinsic_info(id);
 473   int shift = log2_FLAG_LIMIT, mask = right_n_bits(vmSymbols::log2_SID_LIMIT);
 474   assert(((ID4(1021,1022,1023,15) >> shift) & mask) == 1023, "");
 475   return vmSymbols::SID( (info >> shift) & mask );
 476 }
 477 
 478 vmIntrinsics::Flags vmIntrinsics::flags_for(vmIntrinsics::ID id) {
 479   jlong info = intrinsic_info(id);
 480   int shift = 0, mask = right_n_bits(log2_FLAG_LIMIT);
 481   assert(((ID4(1021,1022,1023,15) >> shift) & mask) == 15, "");
 482   return Flags( (info >> shift) & mask );
 483 }
 484 
 485 
 486 #ifndef PRODUCT
 487 // verify_method performs an extra check on a matched intrinsic method
 488 
 489 static bool match_method(Method* m, Symbol* n, Symbol* s) {
 490   return (m->name() == n &&
 491           m->signature() == s);
 492 }
 493 
 494 static vmIntrinsics::ID match_method_with_klass(Method* m, Symbol* mk) {
 495 #define VM_INTRINSIC_MATCH(id, klassname, namepart, sigpart, flags) \
 496   { Symbol* k = vmSymbols::klassname(); \
 497     if (mk == k) { \
 498       Symbol* n = vmSymbols::namepart(); \
 499       Symbol* s = vmSymbols::sigpart(); \
 500       if (match_method(m, n, s)) \
 501         return vmIntrinsics::id; \
 502     } }
 503   VM_INTRINSICS_DO(VM_INTRINSIC_MATCH,
 504                    VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
 505   return vmIntrinsics::_none;
 506 #undef VM_INTRINSIC_MATCH
 507 }
 508 
 509 void vmIntrinsics::verify_method(ID actual_id, Method* m) {
 510   Symbol* mk = m->method_holder()->name();
 511   ID declared_id = match_method_with_klass(m, mk);
 512 
 513   if (declared_id == actual_id)  return; // success
 514 
 515   if (declared_id == _none && actual_id != _none && mk == vmSymbols::java_lang_StrictMath()) {
 516     // Here are a few special cases in StrictMath not declared in vmSymbols.hpp.
 517     switch (actual_id) {
 518     case _min:
 519     case _max:
 520     case _dsqrt:
 521       declared_id = match_method_with_klass(m, vmSymbols::java_lang_Math());
 522       if (declared_id == actual_id)  return; // acceptable alias
 523       break;
 524     }
 525   }
 526 
 527   const char* declared_name = name_at(declared_id);
 528   const char* actual_name   = name_at(actual_id);
 529   methodHandle mh = m;
 530   m = NULL;
 531   ttyLocker ttyl;
 532   if (xtty != NULL) {
 533     xtty->begin_elem("intrinsic_misdeclared actual='%s' declared='%s'",
 534                      actual_name, declared_name);
 535     xtty->method(mh);


  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  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/vmSymbols.hpp"
  27 #include "memory/oopFactory.hpp"
  28 #include "oops/oop.inline.hpp"
  29 #include "runtime/handles.inline.hpp"
  30 #include "utilities/xmlstream.hpp"
  31 
  32 
  33 Symbol* vmSymbols::_symbols[vmSymbols::SID_LIMIT];
  34 
  35 Symbol* vmSymbols::_type_signatures[T_VOID+1] = { NULL /*, NULL...*/ };
  36 
  37 inline int compare_symbol(Symbol* a, Symbol* b) {
  38   if (a->equals(b))  return 0;
  39   // follow the natural address order:
  40   return (address)a > (address)b ? +1 : -1;
  41 }
  42 
  43 static vmSymbols::SID vm_symbol_index[vmSymbols::SID_LIMIT];
  44 extern "C" {
  45   static int compare_vmsymbol_sid(const void* void_a, const void* void_b) {
  46     Symbol* a = vmSymbols::symbol_at(*((vmSymbols::SID*) void_a));
  47     Symbol* b = vmSymbols::symbol_at(*((vmSymbols::SID*) void_b));
  48     return compare_symbol(a, b);
  49   }
  50 }
  51 
  52 #ifdef ASSERT
  53 #define VM_SYMBOL_ENUM_NAME_BODY(name, string) #name "\0"
  54 static const char* vm_symbol_enum_names =
  55   VM_SYMBOLS_DO(VM_SYMBOL_ENUM_NAME_BODY, VM_ALIAS_IGNORE)
  56   "\0";
  57 static const char* vm_symbol_enum_name(vmSymbols::SID sid) {
  58   const char* string = &vm_symbol_enum_names[0];


  85       string += 1;              // skip trailing null
  86     }
  87 
  88     _type_signatures[T_BYTE]    = byte_signature();
  89     _type_signatures[T_CHAR]    = char_signature();
  90     _type_signatures[T_DOUBLE]  = double_signature();
  91     _type_signatures[T_FLOAT]   = float_signature();
  92     _type_signatures[T_INT]     = int_signature();
  93     _type_signatures[T_LONG]    = long_signature();
  94     _type_signatures[T_SHORT]   = short_signature();
  95     _type_signatures[T_BOOLEAN] = bool_signature();
  96     _type_signatures[T_VOID]    = void_signature();
  97     // no single signatures for T_OBJECT or T_ARRAY
  98   }
  99 
 100 #ifdef ASSERT
 101   // Check for duplicates:
 102   for (int i1 = (int)FIRST_SID; i1 < (int)SID_LIMIT; i1++) {
 103     Symbol* sym = symbol_at((SID)i1);
 104     for (int i2 = (int)FIRST_SID; i2 < i1; i2++) {
 105       if (symbol_at((SID)i2)->equals(sym)) {
 106         tty->print("*** Duplicate VM symbol SIDs %s(%d) and %s(%d): \"",
 107                    vm_symbol_enum_name((SID)i2), i2,
 108                    vm_symbol_enum_name((SID)i1), i1);
 109         sym->print_symbol_on(tty);
 110         tty->print_cr("\"");
 111       }
 112     }
 113   }
 114 #endif //ASSERT
 115 
 116   // Create an index for find_id:
 117   {
 118     for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
 119       vm_symbol_index[index] = (SID)index;
 120     }
 121     int num_sids = SID_LIMIT-FIRST_SID;
 122     qsort(&vm_symbol_index[FIRST_SID], num_sids, sizeof(vm_symbol_index[0]),
 123           compare_vmsymbol_sid);
 124   }
 125 


 174 
 175 void vmSymbols::symbols_do(SymbolClosure* f) {
 176   for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
 177     f->do_symbol(&_symbols[index]);
 178   }
 179   for (int i = 0; i < T_VOID+1; i++) {
 180     f->do_symbol(&_type_signatures[i]);
 181   }
 182 }
 183 
 184 void vmSymbols::serialize(SerializeClosure* soc) {
 185   soc->do_region((u_char*)&_symbols[FIRST_SID],
 186                  (SID_LIMIT - FIRST_SID) * sizeof(_symbols[0]));
 187   soc->do_region((u_char*)_type_signatures, sizeof(_type_signatures));
 188 }
 189 
 190 
 191 BasicType vmSymbols::signature_type(Symbol* s) {
 192   assert(s != NULL, "checking");
 193   for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
 194     if (s->equals(_type_signatures[i])) {
 195       return (BasicType)i;
 196     }
 197   }
 198   return T_OBJECT;
 199 }
 200 
 201 
 202 static int mid_hint = (int)vmSymbols::FIRST_SID+1;
 203 
 204 #ifndef PRODUCT
 205 static int find_sid_calls, find_sid_probes;
 206 // (Typical counts are calls=7000 and probes=17000.)
 207 #endif
 208 
 209 vmSymbols::SID vmSymbols::find_sid(Symbol* symbol) {
 210   // Handle the majority of misses by a bounds check.
 211   // Then, use a binary search over the index.
 212   // Expected trip count is less than log2_SID_LIMIT, about eight.
 213   // This is slow but acceptable, given that calls are not
 214   // dynamically common.  (Method*::intrinsic_id has a cache.)


 245           min = mid + 1;
 246 
 247         // Pick a new probe point:
 248         mid = (max + min) / 2;
 249       }
 250     }
 251   }
 252 
 253 #ifdef ASSERT
 254   // Perform the exhaustive self-check the first 1000 calls,
 255   // and every 100 calls thereafter.
 256   static int find_sid_check_count = -2000;
 257   if ((uint)++find_sid_check_count > (uint)100) {
 258     if (find_sid_check_count > 0)  find_sid_check_count = 0;
 259 
 260     // Make sure this is the right answer, using linear search.
 261     // (We have already proven that there are no duplicates in the list.)
 262     SID sid2 = NO_SID;
 263     for (int index = (int)FIRST_SID; index < (int)SID_LIMIT; index++) {
 264       Symbol* sym2 = symbol_at((SID)index);
 265       if (sym2->equals(symbol)) {
 266         sid2 = (SID)index;
 267         break;
 268       }
 269     }
 270     // Unless it's a duplicate, assert that the sids are the same.
 271     if (_symbols[sid]->not_equals(_symbols[sid2])) {
 272       assert(sid == sid2, "binary same as linear search");
 273     }
 274   }
 275 #endif //ASSERT
 276 
 277   return sid;
 278 }
 279 
 280 vmSymbols::SID vmSymbols::find_sid(const char* symbol_name) {
 281   Symbol* symbol = SymbolTable::probe(symbol_name, (int) strlen(symbol_name));
 282   if (symbol == NULL)  return NO_SID;
 283   return find_sid(symbol);
 284 }
 285 
 286 static vmIntrinsics::ID wrapper_intrinsic(BasicType type, bool unboxing) {
 287 #define TYPE2(type, unboxing) ((int)(type)*2 + ((unboxing) ? 1 : 0))
 288   switch (TYPE2(type, unboxing)) {
 289 #define BASIC_TYPE_CASE(type, box, unbox) \
 290     case TYPE2(type, false):  return vmIntrinsics::box; \
 291     case TYPE2(type, true):   return vmIntrinsics::unbox


 470 
 471 vmSymbols::SID vmIntrinsics::signature_for(vmIntrinsics::ID id) {
 472   jlong info = intrinsic_info(id);
 473   int shift = log2_FLAG_LIMIT, mask = right_n_bits(vmSymbols::log2_SID_LIMIT);
 474   assert(((ID4(1021,1022,1023,15) >> shift) & mask) == 1023, "");
 475   return vmSymbols::SID( (info >> shift) & mask );
 476 }
 477 
 478 vmIntrinsics::Flags vmIntrinsics::flags_for(vmIntrinsics::ID id) {
 479   jlong info = intrinsic_info(id);
 480   int shift = 0, mask = right_n_bits(log2_FLAG_LIMIT);
 481   assert(((ID4(1021,1022,1023,15) >> shift) & mask) == 15, "");
 482   return Flags( (info >> shift) & mask );
 483 }
 484 
 485 
 486 #ifndef PRODUCT
 487 // verify_method performs an extra check on a matched intrinsic method
 488 
 489 static bool match_method(Method* m, Symbol* n, Symbol* s) {
 490   return (m->name()->equals(n) &&
 491           m->signature()->equals(s));
 492 }
 493 
 494 static vmIntrinsics::ID match_method_with_klass(Method* m, Symbol* mk) {
 495 #define VM_INTRINSIC_MATCH(id, klassname, namepart, sigpart, flags) \
 496   { Symbol* k = vmSymbols::klassname(); \
 497     if (mk->equals(k)) { \
 498       Symbol* n = vmSymbols::namepart(); \
 499       Symbol* s = vmSymbols::sigpart(); \
 500       if (match_method(m, n, s)) \
 501         return vmIntrinsics::id; \
 502     } }
 503   VM_INTRINSICS_DO(VM_INTRINSIC_MATCH,
 504                    VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
 505   return vmIntrinsics::_none;
 506 #undef VM_INTRINSIC_MATCH
 507 }
 508 
 509 void vmIntrinsics::verify_method(ID actual_id, Method* m) {
 510   Symbol* mk = m->method_holder()->name();
 511   ID declared_id = match_method_with_klass(m, mk);
 512 
 513   if (declared_id == actual_id)  return; // success
 514 
 515   if (declared_id == _none && actual_id != _none && mk->equals(vmSymbols::java_lang_StrictMath())) {
 516     // Here are a few special cases in StrictMath not declared in vmSymbols.hpp.
 517     switch (actual_id) {
 518     case _min:
 519     case _max:
 520     case _dsqrt:
 521       declared_id = match_method_with_klass(m, vmSymbols::java_lang_Math());
 522       if (declared_id == actual_id)  return; // acceptable alias
 523       break;
 524     }
 525   }
 526 
 527   const char* declared_name = name_at(declared_id);
 528   const char* actual_name   = name_at(actual_id);
 529   methodHandle mh = m;
 530   m = NULL;
 531   ttyLocker ttyl;
 532   if (xtty != NULL) {
 533     xtty->begin_elem("intrinsic_misdeclared actual='%s' declared='%s'",
 534                      actual_name, declared_name);
 535     xtty->method(mh);
src/share/vm/classfile/vmSymbols.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File