< prev index next >

src/hotspot/share/oops/instanceKlass.cpp

Print this page
rev 58768 : 8238358: Implementation of JEP 371: Hidden Classes
Reviewed-by: alanb, cjplummer, coleenp, dholmes, dlong, forax, jlahoda, psandoz, plevart, vromero
Contributed-by: mandy.chung@oracle.com, lois.foltan@oracle.com, david.holmes@oracle.com, harold.seigel@oracle.com, serguei.spitsyn@oracle.com, alex.buckley@oracle.com, jamsheed.c.m@oracle.com, jan.lahoda@oracle.com, amy.lu@oracle.com
rev 58769 : imported patch type-descriptor-name


2662 
2663   // If this is an unsafe anonymous class, append a hash to make the name unique
2664   if (is_unsafe_anonymous()) {
2665     intptr_t hash = (java_mirror() != NULL) ? java_mirror()->identity_hash() : 0;
2666     jio_snprintf(hash_buf, sizeof(hash_buf), "/" UINTX_FORMAT, (uintx)hash);
2667     hash_len = (int)strlen(hash_buf);
2668   }
2669 
2670   // Get the internal name as a c string
2671   const char* src = (const char*) (name()->as_C_string());
2672   const int src_length = (int)strlen(src);
2673 
2674   char* dest = NEW_RESOURCE_ARRAY(char, src_length + hash_len + 3);
2675 
2676   // Add L as type indicator
2677   int dest_index = 0;
2678   dest[dest_index++] = JVM_SIGNATURE_CLASS;
2679 
2680   // Add the actual class name
2681   for (int src_index = 0; src_index < src_length; ) {
2682     dest[dest_index++] = src[src_index++];
2683   }
2684 
2685   if (is_hidden()) { // Replace the last '+' with a '.'.
2686     for (int index = (int)src_length; index > 0; index--) {
2687       if (dest[index] == '+') {
2688         dest[index] = JVM_SIGNATURE_DOT;
2689         break;
2690       }
2691     }

2692   }
2693 
2694   // If we have a hash, append it
2695   for (int hash_index = 0; hash_index < hash_len; ) {
2696     dest[dest_index++] = hash_buf[hash_index++];
2697   }
2698 
2699   // Add the semicolon and the NULL

2700   dest[dest_index++] = JVM_SIGNATURE_ENDCLASS;

2701   dest[dest_index] = '\0';
2702   return dest;
2703 }
2704 
2705 ModuleEntry* InstanceKlass::module() const {
2706   // For an unsafe anonymous class return the host class' module
2707   if (is_unsafe_anonymous()) {
2708     assert(unsafe_anonymous_host() != NULL, "unsafe anonymous class must have a host class");
2709     return unsafe_anonymous_host()->module();
2710   }
2711 
2712   if (is_hidden() &&
2713       in_unnamed_package() &&
2714       class_loader_data()->has_class_mirror_holder()) {
2715     // For a non-strong hidden class defined to an unnamed package,
2716     // its (class held) CLD will not have an unnamed module created for it.
2717     // Two choices to find the correct ModuleEntry:
2718     // 1. If hidden class is within a nest, use nest host's module
2719     // 2. Find the unnamed module off from the class loader
2720     // For now option #2 is used since a nest host is not set until




2662 
2663   // If this is an unsafe anonymous class, append a hash to make the name unique
2664   if (is_unsafe_anonymous()) {
2665     intptr_t hash = (java_mirror() != NULL) ? java_mirror()->identity_hash() : 0;
2666     jio_snprintf(hash_buf, sizeof(hash_buf), "/" UINTX_FORMAT, (uintx)hash);
2667     hash_len = (int)strlen(hash_buf);
2668   }
2669 
2670   // Get the internal name as a c string
2671   const char* src = (const char*) (name()->as_C_string());
2672   const int src_length = (int)strlen(src);
2673 
2674   char* dest = NEW_RESOURCE_ARRAY(char, src_length + hash_len + 3);
2675 
2676   // Add L as type indicator
2677   int dest_index = 0;
2678   dest[dest_index++] = JVM_SIGNATURE_CLASS;
2679 
2680   // Add the actual class name
2681   for (int src_index = 0; src_index < src_length; ) {
2682     if (is_hidden() && src[src_index] == '+') {
2683       // Replace the last '+' with a ';' followed with '/'.
2684       dest[dest_index++] = JVM_SIGNATURE_ENDCLASS;
2685       dest[dest_index++] = JVM_SIGNATURE_SLASH;
2686       src_index++;
2687       continue;



2688     } 
2689     dest[dest_index++] = src[src_index++];
2690   }
2691 
2692   // If we have a hash, append it
2693   for (int hash_index = 0; hash_index < hash_len; ) {
2694     dest[dest_index++] = hash_buf[hash_index++];
2695   }
2696 
2697   // Add the semicolon and the NULL
2698   if (!is_hidden()) {
2699     dest[dest_index++] = JVM_SIGNATURE_ENDCLASS;
2700   }
2701   dest[dest_index] = '\0';
2702   return dest;
2703 }
2704 
2705 ModuleEntry* InstanceKlass::module() const {
2706   // For an unsafe anonymous class return the host class' module
2707   if (is_unsafe_anonymous()) {
2708     assert(unsafe_anonymous_host() != NULL, "unsafe anonymous class must have a host class");
2709     return unsafe_anonymous_host()->module();
2710   }
2711 
2712   if (is_hidden() &&
2713       in_unnamed_package() &&
2714       class_loader_data()->has_class_mirror_holder()) {
2715     // For a non-strong hidden class defined to an unnamed package,
2716     // its (class held) CLD will not have an unnamed module created for it.
2717     // Two choices to find the correct ModuleEntry:
2718     // 1. If hidden class is within a nest, use nest host's module
2719     // 2. Find the unnamed module off from the class loader
2720     // For now option #2 is used since a nest host is not set until


< prev index next >