@@ -3253,23 +3253,28 @@ void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3253
3253
// Convenience common pre-built type.
3254
3254
const TypeOopPtr *TypeOopPtr::BOTTOM;
3255
3255
3256
- TypeInterfaces::TypeInterfaces ()
3257
- : Type(Interfaces), _list(Compile::current()->type_arena(), 0, 0, nullptr ),
3256
+ TypeInterfaces::TypeInterfaces (ciInstanceKlass** interfaces_base, int nb_interfaces )
3257
+ : Type(Interfaces), _interfaces(interfaces_base, nb_interfaces ),
3258
3258
_hash(0 ), _exact_klass(nullptr ) {
3259
- DEBUG_ONLY (_initialized = true );
3260
- }
3261
-
3262
- TypeInterfaces::TypeInterfaces (GrowableArray<ciInstanceKlass*>* interfaces)
3263
- : Type(Interfaces), _list(Compile::current()->type_arena(), interfaces->length(), 0, nullptr),
3264
- _hash(0 ), _exact_klass(nullptr ) {
3265
- for (int i = 0 ; i < interfaces->length (); i++) {
3266
- add (interfaces->at (i));
3267
- }
3259
+ _interfaces.sort (compare);
3268
3260
initialize ();
3269
3261
}
3270
3262
3271
3263
const TypeInterfaces* TypeInterfaces::make (GrowableArray<ciInstanceKlass*>* interfaces) {
3272
- TypeInterfaces* result = (interfaces == nullptr ) ? new TypeInterfaces () : new TypeInterfaces (interfaces);
3264
+ // hashcons() can only delete the last thing that was allocated: to
3265
+ // make sure all memory for the newly created TypeInterfaces can be
3266
+ // freed if an identical one exists, allocate space for the array of
3267
+ // interfaces right after the TypeInterfaces object so that they
3268
+ // form a contiguous piece of memory.
3269
+ int nb_interfaces = interfaces == nullptr ? 0 : interfaces->length ();
3270
+ size_t total_size = sizeof (TypeInterfaces) + nb_interfaces * sizeof (ciInstanceKlass*);
3271
+
3272
+ void * allocated_mem = operator new (total_size);
3273
+ ciInstanceKlass** interfaces_base = (ciInstanceKlass**)((char *)allocated_mem + sizeof (TypeInterfaces));
3274
+ for (int i = 0 ; i < nb_interfaces; ++i) {
3275
+ interfaces_base[i] = interfaces->at (i);
3276
+ }
3277
+ TypeInterfaces* result = ::new (allocated_mem) TypeInterfaces (interfaces_base, nb_interfaces);
3273
3278
return (const TypeInterfaces*)result->hashcons ();
3274
3279
}
3275
3280
@@ -3288,20 +3293,18 @@ int TypeInterfaces::compare(ciInstanceKlass* const& k1, ciInstanceKlass* const&
3288
3293
return 0 ;
3289
3294
}
3290
3295
3291
- void TypeInterfaces::add (ciInstanceKlass* interface) {
3292
- assert (interface->is_interface (), " for interfaces only" );
3293
- _list.insert_sorted <compare>(interface);
3294
- verify ();
3296
+ int TypeInterfaces::compare (ciInstanceKlass** k1, ciInstanceKlass** k2) {
3297
+ return compare (*k1, *k2);
3295
3298
}
3296
3299
3297
3300
bool TypeInterfaces::eq (const Type* t) const {
3298
3301
const TypeInterfaces* other = (const TypeInterfaces*)t;
3299
- if (_list .length () != other->_list .length ()) {
3302
+ if (_interfaces .length () != other->_interfaces .length ()) {
3300
3303
return false ;
3301
3304
}
3302
- for (int i = 0 ; i < _list .length (); i++) {
3303
- ciKlass* k1 = _list .at (i);
3304
- ciKlass* k2 = other->_list .at (i);
3305
+ for (int i = 0 ; i < _interfaces .length (); i++) {
3306
+ ciKlass* k1 = _interfaces .at (i);
3307
+ ciKlass* k2 = other->_interfaces .at (i);
3305
3308
if (!k1->equals (k2)) {
3306
3309
return false ;
3307
3310
}
@@ -3312,12 +3315,12 @@ bool TypeInterfaces::eq(const Type* t) const {
3312
3315
bool TypeInterfaces::eq (ciInstanceKlass* k) const {
3313
3316
assert (k->is_loaded (), " should be loaded" );
3314
3317
GrowableArray<ciInstanceKlass *>* interfaces = k->transitive_interfaces ();
3315
- if (_list .length () != interfaces->length ()) {
3318
+ if (_interfaces .length () != interfaces->length ()) {
3316
3319
return false ;
3317
3320
}
3318
3321
for (int i = 0 ; i < interfaces->length (); i++) {
3319
3322
bool found = false ;
3320
- _list .find_sorted <ciInstanceKlass*, compare>(interfaces->at (i), found);
3323
+ _interfaces .find_sorted <ciInstanceKlass*, compare>(interfaces->at (i), found);
3321
3324
if (!found) {
3322
3325
return false ;
3323
3326
}
@@ -3337,8 +3340,8 @@ const Type* TypeInterfaces::xdual() const {
3337
3340
3338
3341
void TypeInterfaces::compute_hash () {
3339
3342
uint hash = 0 ;
3340
- for (int i = 0 ; i < _list .length (); i++) {
3341
- ciKlass* k = _list .at (i);
3343
+ for (int i = 0 ; i < _interfaces .length (); i++) {
3344
+ ciKlass* k = _interfaces .at (i);
3342
3345
hash += k->hash ();
3343
3346
}
3344
3347
_hash = hash;
@@ -3349,13 +3352,13 @@ static int compare_interfaces(ciInstanceKlass** k1, ciInstanceKlass** k2) {
3349
3352
}
3350
3353
3351
3354
void TypeInterfaces::dump (outputStream* st) const {
3352
- if (_list .length () == 0 ) {
3355
+ if (_interfaces .length () == 0 ) {
3353
3356
return ;
3354
3357
}
3355
3358
ResourceMark rm;
3356
3359
st->print (" (" );
3357
3360
GrowableArray<ciInstanceKlass*> interfaces;
3358
- interfaces.appendAll (&_list );
3361
+ interfaces.appendAll (&_interfaces );
3359
3362
// Sort the interfaces so they are listed in the same order from one run to the other of the same compilation
3360
3363
interfaces.sort (compare_interfaces);
3361
3364
for (int i = 0 ; i < interfaces.length (); i++) {
@@ -3370,9 +3373,9 @@ void TypeInterfaces::dump(outputStream* st) const {
3370
3373
3371
3374
#ifdef ASSERT
3372
3375
void TypeInterfaces::verify () const {
3373
- for (int i = 1 ; i < _list .length (); i++) {
3374
- ciInstanceKlass* k1 = _list .at (i-1 );
3375
- ciInstanceKlass* k2 = _list .at (i);
3376
+ for (int i = 1 ; i < _interfaces .length (); i++) {
3377
+ ciInstanceKlass* k1 = _interfaces .at (i-1 );
3378
+ ciInstanceKlass* k2 = _interfaces .at (i);
3376
3379
assert (compare (k2, k1) > 0 , " should be ordered" );
3377
3380
assert (k1 != k2, " no duplicate" );
3378
3381
}
@@ -3383,38 +3386,38 @@ const TypeInterfaces* TypeInterfaces::union_with(const TypeInterfaces* other) co
3383
3386
GrowableArray<ciInstanceKlass*> result_list;
3384
3387
int i = 0 ;
3385
3388
int j = 0 ;
3386
- while (i < _list .length () || j < other->_list .length ()) {
3387
- while (i < _list .length () &&
3388
- (j >= other->_list .length () ||
3389
- compare (_list .at (i), other->_list .at (j)) < 0 )) {
3390
- result_list.push (_list .at (i));
3389
+ while (i < _interfaces .length () || j < other->_interfaces .length ()) {
3390
+ while (i < _interfaces .length () &&
3391
+ (j >= other->_interfaces .length () ||
3392
+ compare (_interfaces .at (i), other->_interfaces .at (j)) < 0 )) {
3393
+ result_list.push (_interfaces .at (i));
3391
3394
i++;
3392
3395
}
3393
- while (j < other->_list .length () &&
3394
- (i >= _list .length () ||
3395
- compare (other->_list .at (j), _list .at (i)) < 0 )) {
3396
- result_list.push (other->_list .at (j));
3396
+ while (j < other->_interfaces .length () &&
3397
+ (i >= _interfaces .length () ||
3398
+ compare (other->_interfaces .at (j), _interfaces .at (i)) < 0 )) {
3399
+ result_list.push (other->_interfaces .at (j));
3397
3400
j++;
3398
3401
}
3399
- if (i < _list .length () &&
3400
- j < other->_list .length () &&
3401
- _list .at (i) == other->_list .at (j)) {
3402
- result_list.push (_list .at (i));
3402
+ if (i < _interfaces .length () &&
3403
+ j < other->_interfaces .length () &&
3404
+ _interfaces .at (i) == other->_interfaces .at (j)) {
3405
+ result_list.push (_interfaces .at (i));
3403
3406
i++;
3404
3407
j++;
3405
3408
}
3406
3409
}
3407
3410
const TypeInterfaces* result = TypeInterfaces::make (&result_list);
3408
3411
#ifdef ASSERT
3409
3412
result->verify ();
3410
- for (int i = 0 ; i < _list .length (); i++) {
3411
- assert (result->_list .contains (_list .at (i)), " missing" );
3413
+ for (int i = 0 ; i < _interfaces .length (); i++) {
3414
+ assert (result->_interfaces .contains (_interfaces .at (i)), " missing" );
3412
3415
}
3413
- for (int i = 0 ; i < other->_list .length (); i++) {
3414
- assert (result->_list .contains (other->_list .at (i)), " missing" );
3416
+ for (int i = 0 ; i < other->_interfaces .length (); i++) {
3417
+ assert (result->_interfaces .contains (other->_interfaces .at (i)), " missing" );
3415
3418
}
3416
- for (int i = 0 ; i < result->_list .length (); i++) {
3417
- assert (_list .contains (result->_list .at (i)) || other->_list .contains (result->_list .at (i)), " missing" );
3419
+ for (int i = 0 ; i < result->_interfaces .length (); i++) {
3420
+ assert (_interfaces .contains (result->_interfaces .at (i)) || other->_interfaces .contains (result->_interfaces .at (i)), " missing" );
3418
3421
}
3419
3422
#endif
3420
3423
return result;
@@ -3424,36 +3427,36 @@ const TypeInterfaces* TypeInterfaces::intersection_with(const TypeInterfaces* ot
3424
3427
GrowableArray<ciInstanceKlass*> result_list;
3425
3428
int i = 0 ;
3426
3429
int j = 0 ;
3427
- while (i < _list .length () || j < other->_list .length ()) {
3428
- while (i < _list .length () &&
3429
- (j >= other->_list .length () ||
3430
- compare (_list .at (i), other->_list .at (j)) < 0 )) {
3430
+ while (i < _interfaces .length () || j < other->_interfaces .length ()) {
3431
+ while (i < _interfaces .length () &&
3432
+ (j >= other->_interfaces .length () ||
3433
+ compare (_interfaces .at (i), other->_interfaces .at (j)) < 0 )) {
3431
3434
i++;
3432
3435
}
3433
- while (j < other->_list .length () &&
3434
- (i >= _list .length () ||
3435
- compare (other->_list .at (j), _list .at (i)) < 0 )) {
3436
+ while (j < other->_interfaces .length () &&
3437
+ (i >= _interfaces .length () ||
3438
+ compare (other->_interfaces .at (j), _interfaces .at (i)) < 0 )) {
3436
3439
j++;
3437
3440
}
3438
- if (i < _list .length () &&
3439
- j < other->_list .length () &&
3440
- _list .at (i) == other->_list .at (j)) {
3441
- result_list.push (_list .at (i));
3441
+ if (i < _interfaces .length () &&
3442
+ j < other->_interfaces .length () &&
3443
+ _interfaces .at (i) == other->_interfaces .at (j)) {
3444
+ result_list.push (_interfaces .at (i));
3442
3445
i++;
3443
3446
j++;
3444
3447
}
3445
3448
}
3446
3449
const TypeInterfaces* result = TypeInterfaces::make (&result_list);
3447
3450
#ifdef ASSERT
3448
3451
result->verify ();
3449
- for (int i = 0 ; i < _list .length (); i++) {
3450
- assert (!other->_list .contains (_list .at (i)) || result->_list .contains (_list .at (i)), " missing" );
3452
+ for (int i = 0 ; i < _interfaces .length (); i++) {
3453
+ assert (!other->_interfaces .contains (_interfaces .at (i)) || result->_interfaces .contains (_interfaces .at (i)), " missing" );
3451
3454
}
3452
- for (int i = 0 ; i < other->_list .length (); i++) {
3453
- assert (!_list .contains (other->_list .at (i)) || result->_list .contains (other->_list .at (i)), " missing" );
3455
+ for (int i = 0 ; i < other->_interfaces .length (); i++) {
3456
+ assert (!_interfaces .contains (other->_interfaces .at (i)) || result->_interfaces .contains (other->_interfaces .at (i)), " missing" );
3454
3457
}
3455
- for (int i = 0 ; i < result->_list .length (); i++) {
3456
- assert (_list .contains (result->_list .at (i)) && other->_list .contains (result->_list .at (i)), " missing" );
3458
+ for (int i = 0 ; i < result->_interfaces .length (); i++) {
3459
+ assert (_interfaces .contains (result->_interfaces .at (i)) && other->_interfaces .contains (result->_interfaces .at (i)), " missing" );
3457
3460
}
3458
3461
#endif
3459
3462
return result;
@@ -3466,13 +3469,13 @@ ciInstanceKlass* TypeInterfaces::exact_klass() const {
3466
3469
}
3467
3470
3468
3471
void TypeInterfaces::compute_exact_klass () {
3469
- if (_list .length () == 0 ) {
3472
+ if (_interfaces .length () == 0 ) {
3470
3473
_exact_klass = nullptr ;
3471
3474
return ;
3472
3475
}
3473
3476
ciInstanceKlass* res = nullptr ;
3474
- for (int i = 0 ; i < _list .length (); i++) {
3475
- ciInstanceKlass* interface = _list .at (i);
3477
+ for (int i = 0 ; i < _interfaces .length (); i++) {
3478
+ ciInstanceKlass* interface = _interfaces .at (i);
3476
3479
if (eq (interface)) {
3477
3480
assert (res == nullptr , " " );
3478
3481
res = interface;
@@ -3483,8 +3486,8 @@ void TypeInterfaces::compute_exact_klass() {
3483
3486
3484
3487
#ifdef ASSERT
3485
3488
void TypeInterfaces::verify_is_loaded () const {
3486
- for (int i = 0 ; i < _list .length (); i++) {
3487
- ciKlass* interface = _list .at (i);
3489
+ for (int i = 0 ; i < _interfaces .length (); i++) {
3490
+ ciKlass* interface = _interfaces .at (i);
3488
3491
assert (interface->is_loaded (), " Interface not loaded" );
3489
3492
}
3490
3493
}
0 commit comments