< prev index next >

src/hotspot/share/ci/ciObjArrayKlass.cpp

Print this page




  48     _element_klass = _base_element_klass;
  49   } else {
  50     _element_klass = NULL;
  51   }
  52   if (!ciObjectFactory::is_initialized()) {
  53     assert(_element_klass->is_java_lang_Object(), "only arrays of object are shared");
  54   }
  55 }
  56 
  57 // ------------------------------------------------------------------
  58 // ciObjArrayKlass::ciObjArrayKlass
  59 //
  60 // Constructor for unloaded object array klasses.
  61 ciObjArrayKlass::ciObjArrayKlass(ciSymbol* array_name,
  62                                  ciKlass* base_element_klass,
  63                                  int dimension)
  64   : ciArrayKlass(array_name,
  65                  dimension, T_OBJECT) {
  66     _base_element_klass = base_element_klass;
  67     assert(_base_element_klass->is_instance_klass() ||
  68            _base_element_klass->is_type_array_klass(), "bad base klass");

  69     if (dimension == 1) {
  70       _element_klass = base_element_klass;
  71     } else {
  72       _element_klass = NULL;
  73     }
  74 }
  75 
  76 // ------------------------------------------------------------------
  77 // ciObjArrayKlass::element_klass
  78 //
  79 // What is the one-level element type of this array?
  80 ciKlass* ciObjArrayKlass::element_klass() {
  81   if (_element_klass == NULL) {
  82     assert(dimension() > 1, "_element_klass should not be NULL");
  83     // Produce the element klass.
  84     if (is_loaded()) {
  85       VM_ENTRY_MARK;
  86       Klass* element_Klass = get_ObjArrayKlass()->element_klass();
  87       _element_klass = CURRENT_THREAD_ENV->get_klass(element_Klass);
  88     } else {


  93                           this,
  94                           constantPoolHandle(),
  95                           construct_array_name(base_element_klass()->name(),
  96                                                dimension() - 1),
  97                           false);
  98     }
  99   }
 100   return _element_klass;
 101 }
 102 
 103 // ------------------------------------------------------------------
 104 // ciObjArrayKlass::construct_array_name
 105 //
 106 // Build an array name from an element name and a dimension.
 107 ciSymbol* ciObjArrayKlass::construct_array_name(ciSymbol* element_name,
 108                                                 int dimension) {
 109   EXCEPTION_CONTEXT;
 110   int element_len = element_name->utf8_length();
 111 
 112   Symbol* base_name_sym = element_name->get_symbol();

 113   char* name;
 114 
 115   if (base_name_sym->char_at(0) == '[' ||
 116       (base_name_sym->char_at(0) == 'L' &&  // watch package name 'Lxx'
 117        base_name_sym->char_at(element_len-1) == ';')) {
 118 
 119     int new_len = element_len + dimension + 1; // for the ['s and '\0'
 120     name = CURRENT_THREAD_ENV->name_buffer(new_len);
 121 
 122     int pos = 0;
 123     for ( ; pos < dimension; pos++) {
 124       name[pos] = '[';
 125     }
 126     strncpy(name+pos, (char*)element_name->base(), element_len);
 127     name[new_len-1] = '\0';
 128   } else {
 129     int new_len =   3                       // for L, ;, and '\0'
 130                   + dimension               // for ['s
 131                   + element_len;
 132 
 133     name = CURRENT_THREAD_ENV->name_buffer(new_len);
 134     int pos = 0;
 135     for ( ; pos < dimension; pos++) {
 136       name[pos] = '[';
 137     }
 138     name[pos++] = 'L';
 139     strncpy(name+pos, (char*)element_name->base(), element_len);
 140     name[new_len-2] = ';';
 141     name[new_len-1] = '\0';
 142   }
 143   return ciSymbol::make(name);
 144 }
 145 
 146 // ------------------------------------------------------------------
 147 // ciObjArrayKlass::make_impl
 148 //
 149 // Implementation of make.
 150 ciObjArrayKlass* ciObjArrayKlass::make_impl(ciKlass* element_klass) {
 151 
 152   if (element_klass->is_loaded()) {
 153     EXCEPTION_CONTEXT;
 154     // The element klass is loaded
 155     Klass* array = element_klass->get_Klass()->array_klass(THREAD);





 156     if (HAS_PENDING_EXCEPTION) {
 157       CLEAR_PENDING_EXCEPTION;
 158       CURRENT_THREAD_ENV->record_out_of_memory_failure();
 159       return ciEnv::unloaded_ciobjarrayklass();
 160     }
 161     return CURRENT_THREAD_ENV->get_obj_array_klass(array);
 162   }
 163 
 164   // The array klass was unable to be made or the element klass was
 165   // not loaded.
 166   ciSymbol* array_name = construct_array_name(element_klass->name(), 1);
 167   if (array_name == ciEnv::unloaded_cisymbol()) {
 168     return ciEnv::unloaded_ciobjarrayklass();
 169   }
 170   return
 171     CURRENT_ENV->get_unloaded_klass(element_klass, array_name)
 172                         ->as_obj_array_klass();
 173 }
 174 
 175 // ------------------------------------------------------------------
 176 // ciObjArrayKlass::make
 177 //
 178 // Make an array klass corresponding to the specified primitive type.
 179 ciObjArrayKlass* ciObjArrayKlass::make(ciKlass* element_klass) {
 180   GUARDED_VM_ENTRY(return make_impl(element_klass);)
 181 }
 182 
 183 ciKlass* ciObjArrayKlass::exact_klass() {
 184   ciType* base = base_element_type();
 185   if (base->is_instance_klass()) {
 186     ciInstanceKlass* ik = base->as_instance_klass();
 187     if (ik->exact_klass() != NULL) {
 188       return this;
 189     }
 190   } else if (base->is_primitive_type()) {
 191     return this;
 192   }
 193   return NULL;
 194 }


  48     _element_klass = _base_element_klass;
  49   } else {
  50     _element_klass = NULL;
  51   }
  52   if (!ciObjectFactory::is_initialized()) {
  53     assert(_element_klass->is_java_lang_Object(), "only arrays of object are shared");
  54   }
  55 }
  56 
  57 // ------------------------------------------------------------------
  58 // ciObjArrayKlass::ciObjArrayKlass
  59 //
  60 // Constructor for unloaded object array klasses.
  61 ciObjArrayKlass::ciObjArrayKlass(ciSymbol* array_name,
  62                                  ciKlass* base_element_klass,
  63                                  int dimension)
  64   : ciArrayKlass(array_name,
  65                  dimension, T_OBJECT) {
  66     _base_element_klass = base_element_klass;
  67     assert(_base_element_klass->is_instance_klass() ||
  68            _base_element_klass->is_type_array_klass() ||
  69            _base_element_klass->is_value_array_klass(), "bad base klass");
  70     if (dimension == 1) {
  71       _element_klass = base_element_klass;
  72     } else {
  73       _element_klass = NULL;
  74     }
  75 }
  76 
  77 // ------------------------------------------------------------------
  78 // ciObjArrayKlass::element_klass
  79 //
  80 // What is the one-level element type of this array?
  81 ciKlass* ciObjArrayKlass::element_klass() {
  82   if (_element_klass == NULL) {
  83     assert(dimension() > 1, "_element_klass should not be NULL");
  84     // Produce the element klass.
  85     if (is_loaded()) {
  86       VM_ENTRY_MARK;
  87       Klass* element_Klass = get_ObjArrayKlass()->element_klass();
  88       _element_klass = CURRENT_THREAD_ENV->get_klass(element_Klass);
  89     } else {


  94                           this,
  95                           constantPoolHandle(),
  96                           construct_array_name(base_element_klass()->name(),
  97                                                dimension() - 1),
  98                           false);
  99     }
 100   }
 101   return _element_klass;
 102 }
 103 
 104 // ------------------------------------------------------------------
 105 // ciObjArrayKlass::construct_array_name
 106 //
 107 // Build an array name from an element name and a dimension.
 108 ciSymbol* ciObjArrayKlass::construct_array_name(ciSymbol* element_name,
 109                                                 int dimension) {
 110   EXCEPTION_CONTEXT;
 111   int element_len = element_name->utf8_length();
 112 
 113   Symbol* base_name_sym = element_name->get_symbol();
 114   assert(base_name_sym->char_at(0) != 'Q', "unloaded array klass element should not have Q-type");
 115   char* name;
 116 
 117   if (base_name_sym->char_at(0) == '[' ||
 118       (base_name_sym->char_at(0) == 'L' &&  // watch package name 'Lxx'
 119        base_name_sym->char_at(element_len-1) == ';')) {
 120 
 121     int new_len = element_len + dimension + 1; // for the ['s and '\0'
 122     name = CURRENT_THREAD_ENV->name_buffer(new_len);
 123 
 124     int pos = 0;
 125     for ( ; pos < dimension; pos++) {
 126       name[pos] = '[';
 127     }
 128     strncpy(name+pos, (char*)element_name->base(), element_len);
 129     name[new_len-1] = '\0';
 130   } else {
 131     int new_len =   3                       // for L, ;, and '\0'
 132                   + dimension               // for ['s
 133                   + element_len;
 134 
 135     name = CURRENT_THREAD_ENV->name_buffer(new_len);
 136     int pos = 0;
 137     for ( ; pos < dimension; pos++) {
 138       name[pos] = '[';
 139     }
 140     name[pos++] = 'L';
 141     strncpy(name+pos, (char*)element_name->base(), element_len);
 142     name[new_len-2] = ';';
 143     name[new_len-1] = '\0';
 144   }
 145   return ciSymbol::make(name);
 146 }
 147 
 148 // ------------------------------------------------------------------
 149 // ciObjArrayKlass::make_impl
 150 //
 151 // Implementation of make.
 152 ciObjArrayKlass* ciObjArrayKlass::make_impl(ciKlass* element_klass, bool never_null) {

 153   if (element_klass->is_loaded()) {
 154     EXCEPTION_CONTEXT;
 155     // The element klass is loaded
 156     ArrayStorageProperties props = never_null ? ArrayStorageProperties::flattened_and_null_free : ArrayStorageProperties::empty;
 157     Klass* array = element_klass->get_Klass()->array_klass(props, THREAD);
 158     if (element_klass->is_valuetype()) {
 159       assert(!ObjArrayKlass::cast(array)->storage_properties().is_flattened(), "should not be flattened");
 160       assert(ObjArrayKlass::cast(array)->storage_properties().is_null_free() == never_null, "wrong nullability storage property");
 161     }
 162     if (HAS_PENDING_EXCEPTION) {
 163       CLEAR_PENDING_EXCEPTION;
 164       CURRENT_THREAD_ENV->record_out_of_memory_failure();
 165       return ciEnv::unloaded_ciobjarrayklass();
 166     }
 167     return CURRENT_THREAD_ENV->get_obj_array_klass(array);
 168   }
 169 
 170   // The array klass was unable to be made or the element klass was not loaded.

 171   ciSymbol* array_name = construct_array_name(element_klass->name(), 1);
 172   if (array_name == ciEnv::unloaded_cisymbol()) {
 173     return ciEnv::unloaded_ciobjarrayklass();
 174   }
 175   return
 176     CURRENT_ENV->get_unloaded_klass(element_klass, array_name)
 177                         ->as_obj_array_klass();
 178 }
 179 
 180 // ------------------------------------------------------------------
 181 // ciObjArrayKlass::make
 182 //
 183 // Make an array klass corresponding to the specified primitive type.
 184 ciObjArrayKlass* ciObjArrayKlass::make(ciKlass* element_klass, bool never_null) {
 185   GUARDED_VM_ENTRY(return make_impl(element_klass, never_null);)
 186 }
 187 
 188 ciKlass* ciObjArrayKlass::exact_klass() {
 189   ciType* base = base_element_type();
 190   if (base->is_instance_klass()) {
 191     ciInstanceKlass* ik = base->as_instance_klass();
 192     if (ik->exact_klass() != NULL) {
 193       return this;
 194     }
 195   } else if (base->is_primitive_type()) {
 196     return this;
 197   }
 198   return NULL;
 199 }
< prev index next >