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 *
23 */
24
25 #include "precompiled.hpp"
26 #include "ci/ciConstant.hpp"
27 #include "ci/ciEnv.hpp"
28 #include "ci/ciField.hpp"
29 #include "ci/ciInstance.hpp"
30 #include "ci/ciInstanceKlass.hpp"
31 #include "ci/ciMethod.hpp"
32 #include "ci/ciNullObject.hpp"
33 #include "ci/ciReplay.hpp"
34 #include "ci/ciSymbols.hpp"
35 #include "ci/ciUtilities.inline.hpp"
36 #include "classfile/javaClasses.hpp"
37 #include "classfile/javaClasses.inline.hpp"
38 #include "classfile/systemDictionary.hpp"
39 #include "classfile/vmClasses.hpp"
40 #include "classfile/vmSymbols.hpp"
41 #include "code/codeCache.hpp"
42 #include "code/scopeDesc.hpp"
43 #include "compiler/compilationLog.hpp"
44 #include "compiler/compilationPolicy.hpp"
45 #include "compiler/compileBroker.hpp"
46 #include "compiler/compilerEvent.hpp"
47 #include "compiler/compileLog.hpp"
48 #include "compiler/compileTask.hpp"
510 }
511
512 Handle loader;
513 Handle domain;
514 if (accessing_klass != nullptr) {
515 loader = Handle(current, accessing_klass->loader());
516 domain = Handle(current, accessing_klass->protection_domain());
517 }
518
519 Klass* found_klass = require_local ?
520 SystemDictionary::find_instance_or_array_klass(current, sym, loader, domain) :
521 SystemDictionary::find_constrained_instance_or_array_klass(current, sym, loader);
522
523 // If we fail to find an array klass, look again for its element type.
524 // The element type may be available either locally or via constraints.
525 // In either case, if we can find the element type in the system dictionary,
526 // we must build an array type around it. The CI requires array klasses
527 // to be loaded if their element klasses are loaded, except when memory
528 // is exhausted.
529 if (Signature::is_array(sym) &&
530 (sym->char_at(1) == JVM_SIGNATURE_ARRAY || sym->char_at(1) == JVM_SIGNATURE_CLASS)) {
531 // We have an unloaded array.
532 // Build it on the fly if the element class exists.
533 SignatureStream ss(sym, false);
534 ss.skip_array_prefix(1);
535 // Get element ciKlass recursively.
536 ciKlass* elem_klass =
537 get_klass_by_name_impl(accessing_klass,
538 cpool,
539 get_symbol(ss.as_symbol()),
540 require_local);
541 if (elem_klass != nullptr && elem_klass->is_loaded()) {
542 // Now make an array for it
543 return ciObjArrayKlass::make_impl(elem_klass);
544 }
545 }
546
547 if (found_klass == nullptr && !cpool.is_null() && cpool->has_preresolution()) {
548 // Look inside the constant pool for pre-resolved class entries.
549 for (int i = cpool->length() - 1; i >= 1; i--) {
550 if (cpool->tag_at(i).is_klass()) {
551 Klass* kls = cpool->resolved_klass_at(i);
552 if (kls->name() == sym) {
553 found_klass = kls;
554 break;
555 }
556 }
557 }
558 }
559
560 if (found_klass != nullptr) {
561 // Found it. Build a CI handle.
562 return get_klass(found_klass);
563 }
564
565 if (require_local) return nullptr;
566
567 // Not yet loaded into the VM, or not governed by loader constraints.
568 // Make a CI representative for it.
569 return get_unloaded_klass(accessing_klass, name);
570 }
571
572 // ------------------------------------------------------------------
573 // ciEnv::get_klass_by_name
574 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass,
575 ciSymbol* klass_name,
576 bool require_local) {
577 GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass,
578 constantPoolHandle(),
579 klass_name,
580 require_local);)
581 }
582
583 // ------------------------------------------------------------------
584 // ciEnv::get_klass_by_index_impl
585 //
586 // Implementation of get_klass_by_index.
587 ciKlass* ciEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
588 int index,
|
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 *
23 */
24
25 #include "precompiled.hpp"
26 #include "ci/ciConstant.hpp"
27 #include "ci/ciEnv.hpp"
28 #include "ci/ciField.hpp"
29 #include "ci/ciInlineKlass.hpp"
30 #include "ci/ciInstance.hpp"
31 #include "ci/ciInstanceKlass.hpp"
32 #include "ci/ciMethod.hpp"
33 #include "ci/ciNullObject.hpp"
34 #include "ci/ciReplay.hpp"
35 #include "ci/ciSymbols.hpp"
36 #include "ci/ciUtilities.inline.hpp"
37 #include "classfile/javaClasses.hpp"
38 #include "classfile/javaClasses.inline.hpp"
39 #include "classfile/systemDictionary.hpp"
40 #include "classfile/vmClasses.hpp"
41 #include "classfile/vmSymbols.hpp"
42 #include "code/codeCache.hpp"
43 #include "code/scopeDesc.hpp"
44 #include "compiler/compilationLog.hpp"
45 #include "compiler/compilationPolicy.hpp"
46 #include "compiler/compileBroker.hpp"
47 #include "compiler/compilerEvent.hpp"
48 #include "compiler/compileLog.hpp"
49 #include "compiler/compileTask.hpp"
511 }
512
513 Handle loader;
514 Handle domain;
515 if (accessing_klass != nullptr) {
516 loader = Handle(current, accessing_klass->loader());
517 domain = Handle(current, accessing_klass->protection_domain());
518 }
519
520 Klass* found_klass = require_local ?
521 SystemDictionary::find_instance_or_array_klass(current, sym, loader, domain) :
522 SystemDictionary::find_constrained_instance_or_array_klass(current, sym, loader);
523
524 // If we fail to find an array klass, look again for its element type.
525 // The element type may be available either locally or via constraints.
526 // In either case, if we can find the element type in the system dictionary,
527 // we must build an array type around it. The CI requires array klasses
528 // to be loaded if their element klasses are loaded, except when memory
529 // is exhausted.
530 if (Signature::is_array(sym) &&
531 (sym->char_at(1) == JVM_SIGNATURE_ARRAY ||
532 sym->char_at(1) == JVM_SIGNATURE_CLASS )) {
533 // We have an unloaded array.
534 // Build it on the fly if the element class exists.
535 SignatureStream ss(sym, false);
536 ss.skip_array_prefix(1);
537 // Get element ciKlass recursively.
538 ciKlass* elem_klass =
539 get_klass_by_name_impl(accessing_klass,
540 cpool,
541 get_symbol(ss.as_symbol()),
542 require_local);
543 if (elem_klass != nullptr && elem_klass->is_loaded()) {
544 // Now make an array for it
545 return ciArrayKlass::make(elem_klass);
546 }
547 }
548
549 if (found_klass == nullptr && !cpool.is_null() && cpool->has_preresolution()) {
550 // Look inside the constant pool for pre-resolved class entries.
551 for (int i = cpool->length() - 1; i >= 1; i--) {
552 if (cpool->tag_at(i).is_klass()) {
553 Klass* kls = cpool->resolved_klass_at(i);
554 if (kls->name() == sym) {
555 found_klass = kls;
556 break;
557 }
558 }
559 }
560 }
561
562 if (found_klass != nullptr) {
563 // Found it. Build a CI handle.
564 return get_klass(found_klass);
565 }
566
567 if (require_local) return nullptr;
568
569 // Not yet loaded into the VM, or not governed by loader constraints.
570 // Make a CI representative for it.
571 int i = 0;
572 while (sym->char_at(i) == JVM_SIGNATURE_ARRAY) {
573 i++;
574 }
575 return get_unloaded_klass(accessing_klass, name);
576 }
577
578 // ------------------------------------------------------------------
579 // ciEnv::get_klass_by_name
580 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass,
581 ciSymbol* klass_name,
582 bool require_local) {
583 GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass,
584 constantPoolHandle(),
585 klass_name,
586 require_local);)
587 }
588
589 // ------------------------------------------------------------------
590 // ciEnv::get_klass_by_index_impl
591 //
592 // Implementation of get_klass_by_index.
593 ciKlass* ciEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
594 int index,
|