1 /*
2 * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
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 *
459
460 // Get element ciKlass recursively.
461 ciKlass* elem_klass =
462 get_klass_by_name_impl(accessing_klass,
463 cpool,
464 get_symbol(elem_sym),
465 require_local);
466 if (elem_klass != NULL && elem_klass->is_loaded()) {
467 // Now make an array for it
468 if (elem_klass->is_valuetype() && elem_klass->as_value_klass()->flatten_array()) {
469 return ciValueArrayKlass::make_impl(elem_klass);
470 } else {
471 return ciObjArrayKlass::make_impl(elem_klass);
472 }
473 }
474 }
475
476 if (found_klass == NULL && !cpool.is_null() && cpool->has_preresolution()) {
477 // Look inside the constant pool for pre-resolved class entries.
478 for (int i = cpool->length() - 1; i >= 1; i--) {
479 if (cpool->tag_at(i).is_klass() || cpool->tag_at(i).is_value_type()) {
480 Klass* kls = cpool->resolved_klass_at(i);
481 if (kls->name() == sym) {
482 found_klass = kls;
483 break;
484 }
485 }
486 }
487 }
488
489 if (found_klass != NULL) {
490 // Found it. Build a CI handle.
491 return get_klass(found_klass);
492 }
493
494 if (require_local) return NULL;
495
496 // Not yet loaded into the VM, or not governed by loader constraints.
497 // Make a CI representative for it.
498 int i = 0;
499 while (sym->byte_at(i) == '[') {
500 i++;
501 }
502 if (i > 0 && sym->byte_at(i) == 'Q') {
503 assert(EnableValhalla || EnableMVT, "only for value types");
504 // An unloaded array class of value types is an ObjArrayKlass, an
505 // unloaded value type class is an InstanceKlass. For consistency,
506 // make the signature of the unloaded array of value type use L
507 // rather than Q.
508 char *new_name = CURRENT_THREAD_ENV->name_buffer(sym->utf8_length()+1);
509 strncpy(new_name, (char*)sym->base(), sym->utf8_length());
510 new_name[i] = 'L';
511 new_name[sym->utf8_length()] = '\0';
512 return get_unloaded_klass(accessing_klass, ciSymbol::make(new_name));
513 }
514 return get_unloaded_klass(accessing_klass, name);
515 }
516
517 // ------------------------------------------------------------------
518 // ciEnv::get_klass_by_name
519 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass,
520 ciSymbol* klass_name,
521 bool require_local) {
522 GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass,
523 constantPoolHandle(),
524 klass_name,
525 require_local);)
526 }
527
528 // ------------------------------------------------------------------
529 // ciEnv::get_klass_by_index_impl
530 //
531 // Implementation of get_klass_by_index.
532 ciKlass* ciEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
533 int index,
654 } else if (tag.is_string()) {
655 oop string = NULL;
656 assert(cache_index >= 0, "should have a cache index");
657 if (cpool->is_pseudo_string_at(index)) {
658 string = cpool->pseudo_string_at(index, cache_index);
659 } else {
660 string = cpool->string_at(index, cache_index, THREAD);
661 if (HAS_PENDING_EXCEPTION) {
662 CLEAR_PENDING_EXCEPTION;
663 record_out_of_memory_failure();
664 return ciConstant();
665 }
666 }
667 ciObject* constant = get_object(string);
668 if (constant->is_array()) {
669 return ciConstant(T_ARRAY, constant);
670 } else {
671 assert (constant->is_instance(), "must be an instance, or not? ");
672 return ciConstant(T_OBJECT, constant);
673 }
674 } else if (tag.is_klass() || tag.is_unresolved_klass() ||
675 tag.is_value_type() || tag.is_unresolved_value_type()) {
676 // 4881222: allow ldc to take a class type
677 ciKlass* klass = get_klass_by_index_impl(cpool, index, ignore_will_link, accessor);
678 if (HAS_PENDING_EXCEPTION) {
679 CLEAR_PENDING_EXCEPTION;
680 record_out_of_memory_failure();
681 return ciConstant();
682 }
683 assert (klass->is_instance_klass() || klass->is_array_klass(),
684 "must be an instance or array klass ");
685 return ciConstant(T_OBJECT, klass->java_mirror());
686 } else if (tag.is_method_type()) {
687 // must execute Java code to link this CP entry into cache[i].f1
688 ciSymbol* signature = get_symbol(cpool->method_type_signature_at(index));
689 ciObject* ciobj = get_unloaded_method_type_constant(signature);
690 return ciConstant(T_OBJECT, ciobj);
691 } else if (tag.is_method_handle()) {
692 // must execute Java code to link this CP entry into cache[i].f1
693 int ref_kind = cpool->method_handle_ref_kind_at(index);
694 int callee_index = cpool->method_handle_klass_index_at(index);
695 ciKlass* callee = get_klass_by_index_impl(cpool, callee_index, ignore_will_link, accessor);
|
1 /*
2 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
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 *
459
460 // Get element ciKlass recursively.
461 ciKlass* elem_klass =
462 get_klass_by_name_impl(accessing_klass,
463 cpool,
464 get_symbol(elem_sym),
465 require_local);
466 if (elem_klass != NULL && elem_klass->is_loaded()) {
467 // Now make an array for it
468 if (elem_klass->is_valuetype() && elem_klass->as_value_klass()->flatten_array()) {
469 return ciValueArrayKlass::make_impl(elem_klass);
470 } else {
471 return ciObjArrayKlass::make_impl(elem_klass);
472 }
473 }
474 }
475
476 if (found_klass == NULL && !cpool.is_null() && cpool->has_preresolution()) {
477 // Look inside the constant pool for pre-resolved class entries.
478 for (int i = cpool->length() - 1; i >= 1; i--) {
479 if (cpool->tag_at(i).is_klass()) {
480 Klass* kls = cpool->resolved_klass_at(i);
481 if (kls->name() == sym) {
482 found_klass = kls;
483 break;
484 }
485 }
486 }
487 }
488
489 if (found_klass != NULL) {
490 // Found it. Build a CI handle.
491 return get_klass(found_klass);
492 }
493
494 if (require_local) return NULL;
495
496 // Not yet loaded into the VM, or not governed by loader constraints.
497 // Make a CI representative for it.
498 int i = 0;
499 while (sym->byte_at(i) == '[') {
500 i++;
501 }
502 return get_unloaded_klass(accessing_klass, name);
503 }
504
505 // ------------------------------------------------------------------
506 // ciEnv::get_klass_by_name
507 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass,
508 ciSymbol* klass_name,
509 bool require_local) {
510 GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass,
511 constantPoolHandle(),
512 klass_name,
513 require_local);)
514 }
515
516 // ------------------------------------------------------------------
517 // ciEnv::get_klass_by_index_impl
518 //
519 // Implementation of get_klass_by_index.
520 ciKlass* ciEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
521 int index,
642 } else if (tag.is_string()) {
643 oop string = NULL;
644 assert(cache_index >= 0, "should have a cache index");
645 if (cpool->is_pseudo_string_at(index)) {
646 string = cpool->pseudo_string_at(index, cache_index);
647 } else {
648 string = cpool->string_at(index, cache_index, THREAD);
649 if (HAS_PENDING_EXCEPTION) {
650 CLEAR_PENDING_EXCEPTION;
651 record_out_of_memory_failure();
652 return ciConstant();
653 }
654 }
655 ciObject* constant = get_object(string);
656 if (constant->is_array()) {
657 return ciConstant(T_ARRAY, constant);
658 } else {
659 assert (constant->is_instance(), "must be an instance, or not? ");
660 return ciConstant(T_OBJECT, constant);
661 }
662 } else if (tag.is_klass() || tag.is_unresolved_klass()) {
663 // 4881222: allow ldc to take a class type
664 ciKlass* klass = get_klass_by_index_impl(cpool, index, ignore_will_link, accessor);
665 if (HAS_PENDING_EXCEPTION) {
666 CLEAR_PENDING_EXCEPTION;
667 record_out_of_memory_failure();
668 return ciConstant();
669 }
670 assert (klass->is_instance_klass() || klass->is_array_klass(),
671 "must be an instance or array klass ");
672 return ciConstant(T_OBJECT, klass->java_mirror());
673 } else if (tag.is_method_type()) {
674 // must execute Java code to link this CP entry into cache[i].f1
675 ciSymbol* signature = get_symbol(cpool->method_type_signature_at(index));
676 ciObject* ciobj = get_unloaded_method_type_constant(signature);
677 return ciConstant(T_OBJECT, ciobj);
678 } else if (tag.is_method_handle()) {
679 // must execute Java code to link this CP entry into cache[i].f1
680 int ref_kind = cpool->method_handle_ref_kind_at(index);
681 int callee_index = cpool->method_handle_klass_index_at(index);
682 ciKlass* callee = get_klass_by_index_impl(cpool, callee_index, ignore_will_link, accessor);
|