1 /* |
1 /* |
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
1144 Symbol* sig, AccessFlags flags, int max_stack, int params, |
1144 Symbol* sig, AccessFlags flags, int max_stack, int params, |
1145 ConstMethod::MethodType mt, TRAPS) { |
1145 ConstMethod::MethodType mt, TRAPS) { |
1146 |
1146 |
1147 address code_start = static_cast<address>(bytecodes->adr_at(0)); |
1147 address code_start = static_cast<address>(bytecodes->adr_at(0)); |
1148 int code_length = bytecodes->length(); |
1148 int code_length = bytecodes->length(); |
|
1149 InlineTableSizes sizes; |
1149 |
1150 |
1150 Method* m = Method::allocate(cp->pool_holder()->class_loader_data(), |
1151 Method* m = Method::allocate(cp->pool_holder()->class_loader_data(), |
1151 code_length, flags, 0, 0, 0, 0, 0, 0, |
1152 code_length, flags, &sizes, |
1152 mt, CHECK_NULL); |
1153 mt, CHECK_NULL); |
1153 |
1154 |
1154 m->set_constants(NULL); // This will get filled in later |
1155 m->set_constants(NULL); // This will get filled in later |
1155 m->set_name_index(cp->utf8(name)); |
1156 m->set_name_index(cp->utf8(name)); |
1156 m->set_signature_index(cp->utf8(sig)); |
1157 m->set_signature_index(cp->utf8(sig)); |
1283 static void merge_in_new_methods(InstanceKlass* klass, |
1284 static void merge_in_new_methods(InstanceKlass* klass, |
1284 GrowableArray<Method*>* new_methods, TRAPS) { |
1285 GrowableArray<Method*>* new_methods, TRAPS) { |
1285 |
1286 |
1286 enum { ANNOTATIONS, PARAMETERS, DEFAULTS, NUM_ARRAYS }; |
1287 enum { ANNOTATIONS, PARAMETERS, DEFAULTS, NUM_ARRAYS }; |
1287 |
1288 |
1288 Array<AnnotationArray*>* original_annots[NUM_ARRAYS] = { NULL }; |
|
1289 |
|
1290 Array<Method*>* original_methods = klass->methods(); |
1289 Array<Method*>* original_methods = klass->methods(); |
1291 Annotations* annots = klass->annotations(); |
|
1292 if (annots != NULL) { |
|
1293 original_annots[ANNOTATIONS] = annots->methods_annotations(); |
|
1294 original_annots[PARAMETERS] = annots->methods_parameter_annotations(); |
|
1295 original_annots[DEFAULTS] = annots->methods_default_annotations(); |
|
1296 } |
|
1297 |
|
1298 Array<int>* original_ordering = klass->method_ordering(); |
1290 Array<int>* original_ordering = klass->method_ordering(); |
1299 Array<int>* merged_ordering = Universe::the_empty_int_array(); |
1291 Array<int>* merged_ordering = Universe::the_empty_int_array(); |
1300 |
1292 |
1301 int new_size = klass->methods()->length() + new_methods->length(); |
1293 int new_size = klass->methods()->length() + new_methods->length(); |
1302 |
1294 |
1303 Array<AnnotationArray*>* merged_annots[NUM_ARRAYS]; |
|
1304 |
|
1305 Array<Method*>* merged_methods = MetadataFactory::new_array<Method*>( |
1295 Array<Method*>* merged_methods = MetadataFactory::new_array<Method*>( |
1306 klass->class_loader_data(), new_size, NULL, CHECK); |
1296 klass->class_loader_data(), new_size, NULL, CHECK); |
1307 for (int i = 0; i < NUM_ARRAYS; ++i) { |
1297 |
1308 if (original_annots[i] != NULL) { |
|
1309 merged_annots[i] = MetadataFactory::new_array<AnnotationArray*>( |
|
1310 klass->class_loader_data(), new_size, CHECK); |
|
1311 } else { |
|
1312 merged_annots[i] = NULL; |
|
1313 } |
|
1314 } |
|
1315 if (original_ordering != NULL && original_ordering->length() > 0) { |
1298 if (original_ordering != NULL && original_ordering->length() > 0) { |
1316 merged_ordering = MetadataFactory::new_array<int>( |
1299 merged_ordering = MetadataFactory::new_array<int>( |
1317 klass->class_loader_data(), new_size, CHECK); |
1300 klass->class_loader_data(), new_size, CHECK); |
1318 } |
1301 } |
1319 int method_order_index = klass->methods()->length(); |
1302 int method_order_index = klass->methods()->length(); |
1336 |
1319 |
1337 if (orig_method != NULL && |
1320 if (orig_method != NULL && |
1338 (new_method == NULL || orig_method->name() < new_method->name())) { |
1321 (new_method == NULL || orig_method->name() < new_method->name())) { |
1339 merged_methods->at_put(i, orig_method); |
1322 merged_methods->at_put(i, orig_method); |
1340 original_methods->at_put(orig_idx, NULL); |
1323 original_methods->at_put(orig_idx, NULL); |
1341 for (int j = 0; j < NUM_ARRAYS; ++j) { |
|
1342 if (merged_annots[j] != NULL) { |
|
1343 merged_annots[j]->at_put(i, original_annots[j]->at(orig_idx)); |
|
1344 original_annots[j]->at_put(orig_idx, NULL); |
|
1345 } |
|
1346 } |
|
1347 if (merged_ordering->length() > 0) { |
1324 if (merged_ordering->length() > 0) { |
1348 merged_ordering->at_put(i, original_ordering->at(orig_idx)); |
1325 merged_ordering->at_put(i, original_ordering->at(orig_idx)); |
1349 } |
1326 } |
1350 ++orig_idx; |
1327 ++orig_idx; |
1351 } else { |
1328 } else { |
1370 } |
1347 } |
1371 #endif |
1348 #endif |
1372 |
1349 |
1373 // Replace klass methods with new merged lists |
1350 // Replace klass methods with new merged lists |
1374 klass->set_methods(merged_methods); |
1351 klass->set_methods(merged_methods); |
1375 if (annots != NULL) { |
|
1376 annots->set_methods_annotations(merged_annots[ANNOTATIONS]); |
|
1377 annots->set_methods_parameter_annotations(merged_annots[PARAMETERS]); |
|
1378 annots->set_methods_default_annotations(merged_annots[DEFAULTS]); |
|
1379 } else { |
|
1380 assert(merged_annots[ANNOTATIONS] == NULL, "Must be"); |
|
1381 assert(merged_annots[PARAMETERS] == NULL, "Must be"); |
|
1382 assert(merged_annots[DEFAULTS] == NULL, "Must be"); |
|
1383 } |
|
1384 |
1352 |
1385 ClassLoaderData* cld = klass->class_loader_data(); |
1353 ClassLoaderData* cld = klass->class_loader_data(); |
1386 MetadataFactory::free_array(cld, original_methods); |
1354 MetadataFactory::free_array(cld, original_methods); |
1387 for (int i = 0; i < NUM_ARRAYS; ++i) { |
|
1388 MetadataFactory::free_array(cld, original_annots[i]); |
|
1389 } |
|
1390 if (original_ordering->length() > 0) { |
1355 if (original_ordering->length() > 0) { |
1391 klass->set_method_ordering(merged_ordering); |
1356 klass->set_method_ordering(merged_ordering); |
1392 MetadataFactory::free_array(cld, original_ordering); |
1357 MetadataFactory::free_array(cld, original_ordering); |
1393 } |
1358 } |
1394 } |
1359 } |