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 *
23 */
24
25 #include "ci/ciConstant.hpp"
26 #include "ci/ciEnv.hpp"
27 #include "ci/ciField.hpp"
28 #include "ci/ciInstance.hpp"
29 #include "ci/ciInstanceKlass.hpp"
30 #include "ci/ciMethod.hpp"
31 #include "ci/ciNullObject.hpp"
32 #include "ci/ciReplay.hpp"
33 #include "ci/ciSymbols.hpp"
34 #include "ci/ciUtilities.inline.hpp"
35 #include "classfile/javaClasses.hpp"
36 #include "classfile/javaClasses.inline.hpp"
37 #include "classfile/systemDictionary.hpp"
38 #include "classfile/vmClasses.hpp"
39 #include "classfile/vmSymbols.hpp"
40 #include "code/codeCache.hpp"
41 #include "code/scopeDesc.hpp"
42 #include "compiler/compilationLog.hpp"
43 #include "compiler/compilationPolicy.hpp"
44 #include "compiler/compileBroker.hpp"
45 #include "compiler/compileLog.hpp"
46 #include "compiler/compilerEvent.hpp"
47 #include "compiler/compileTask.hpp"
459 if (require_local) return nullptr;
460 return unloaded_klass;
461 }
462
463 Handle loader;
464 if (accessing_klass != nullptr) {
465 loader = Handle(current, accessing_klass->loader());
466 }
467
468 Klass* found_klass = require_local ?
469 SystemDictionary::find_instance_or_array_klass(current, sym, loader) :
470 SystemDictionary::find_constrained_instance_or_array_klass(current, sym, loader);
471
472 // If we fail to find an array klass, look again for its element type.
473 // The element type may be available either locally or via constraints.
474 // In either case, if we can find the element type in the system dictionary,
475 // we must build an array type around it. The CI requires array klasses
476 // to be loaded if their element klasses are loaded, except when memory
477 // is exhausted.
478 if (Signature::is_array(sym) &&
479 (sym->char_at(1) == JVM_SIGNATURE_ARRAY || sym->char_at(1) == JVM_SIGNATURE_CLASS)) {
480 // We have an unloaded array.
481 // Build it on the fly if the element class exists.
482 SignatureStream ss(sym, false);
483 ss.skip_array_prefix(1);
484 // Get element ciKlass recursively.
485 ciKlass* elem_klass =
486 get_klass_by_name_impl(accessing_klass,
487 cpool,
488 get_symbol(ss.as_symbol()),
489 require_local);
490 if (elem_klass != nullptr && elem_klass->is_loaded()) {
491 // Now make an array for it
492 return ciObjArrayKlass::make_impl(elem_klass);
493 }
494 }
495
496 if (found_klass == nullptr && !cpool.is_null() && cpool->has_preresolution()) {
497 // Look inside the constant pool for pre-resolved class entries.
498 for (int i = cpool->length() - 1; i >= 1; i--) {
499 if (cpool->tag_at(i).is_klass()) {
500 Klass* kls = cpool->resolved_klass_at(i);
501 if (kls->name() == sym) {
502 found_klass = kls;
503 break;
504 }
505 }
506 }
507 }
508
509 if (found_klass != nullptr) {
510 // Found it. Build a CI handle.
511 return get_klass(found_klass);
512 }
513
514 if (require_local) return nullptr;
515
516 // Not yet loaded into the VM, or not governed by loader constraints.
517 // Make a CI representative for it.
518 return get_unloaded_klass(accessing_klass, name);
519 }
520
521 // ------------------------------------------------------------------
522 // ciEnv::get_klass_by_name
523 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass,
524 ciSymbol* klass_name,
525 bool require_local) {
526 GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass,
527 constantPoolHandle(),
528 klass_name,
529 require_local);)
530 }
531
532 // ------------------------------------------------------------------
533 // ciEnv::get_klass_by_index_impl
534 //
535 // Implementation of get_klass_by_index.
536 ciKlass* ciEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
537 int index,
|
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 *
23 */
24
25 #include "ci/ciConstant.hpp"
26 #include "ci/ciEnv.hpp"
27 #include "ci/ciField.hpp"
28 #include "ci/ciInlineKlass.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/compileLog.hpp"
47 #include "compiler/compilerEvent.hpp"
48 #include "compiler/compileTask.hpp"
460 if (require_local) return nullptr;
461 return unloaded_klass;
462 }
463
464 Handle loader;
465 if (accessing_klass != nullptr) {
466 loader = Handle(current, accessing_klass->loader());
467 }
468
469 Klass* found_klass = require_local ?
470 SystemDictionary::find_instance_or_array_klass(current, sym, loader) :
471 SystemDictionary::find_constrained_instance_or_array_klass(current, sym, loader);
472
473 // If we fail to find an array klass, look again for its element type.
474 // The element type may be available either locally or via constraints.
475 // In either case, if we can find the element type in the system dictionary,
476 // we must build an array type around it. The CI requires array klasses
477 // to be loaded if their element klasses are loaded, except when memory
478 // is exhausted.
479 if (Signature::is_array(sym) &&
480 (sym->char_at(1) == JVM_SIGNATURE_ARRAY ||
481 sym->char_at(1) == JVM_SIGNATURE_CLASS )) {
482 // We have an unloaded array.
483 // Build it on the fly if the element class exists.
484 SignatureStream ss(sym, false);
485 ss.skip_array_prefix(1);
486 // Get element ciKlass recursively.
487 ciKlass* elem_klass =
488 get_klass_by_name_impl(accessing_klass,
489 cpool,
490 get_symbol(ss.as_symbol()),
491 require_local);
492 if (elem_klass != nullptr && elem_klass->is_loaded()) {
493 // Now make an array for it
494 return ciArrayKlass::make(elem_klass);
495 }
496 }
497
498 if (found_klass == nullptr && !cpool.is_null() && cpool->has_preresolution()) {
499 // Look inside the constant pool for pre-resolved class entries.
500 for (int i = cpool->length() - 1; i >= 1; i--) {
501 if (cpool->tag_at(i).is_klass()) {
502 Klass* kls = cpool->resolved_klass_at(i);
503 if (kls->name() == sym) {
504 found_klass = kls;
505 break;
506 }
507 }
508 }
509 }
510
511 if (found_klass != nullptr) {
512 // Found it. Build a CI handle.
513 return get_klass(found_klass);
514 }
515
516 if (require_local) return nullptr;
517
518 // Not yet loaded into the VM, or not governed by loader constraints.
519 // Make a CI representative for it.
520 int i = 0;
521 while (sym->char_at(i) == JVM_SIGNATURE_ARRAY) {
522 i++;
523 }
524 return get_unloaded_klass(accessing_klass, name);
525 }
526
527 // ------------------------------------------------------------------
528 // ciEnv::get_klass_by_name
529 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass,
530 ciSymbol* klass_name,
531 bool require_local) {
532 GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass,
533 constantPoolHandle(),
534 klass_name,
535 require_local);)
536 }
537
538 // ------------------------------------------------------------------
539 // ciEnv::get_klass_by_index_impl
540 //
541 // Implementation of get_klass_by_index.
542 ciKlass* ciEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
543 int index,
|