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 *
23 */
24
25 #include "ci/ciCallSite.hpp"
26 #include "ci/ciInstance.hpp"
27 #include "ci/ciInstanceKlass.hpp"
28 #include "ci/ciMemberName.hpp"
29 #include "ci/ciMethod.hpp"
30 #include "ci/ciMethodData.hpp"
31 #include "ci/ciMethodHandle.hpp"
32 #include "ci/ciMethodType.hpp"
33 #include "ci/ciNullObject.hpp"
34 #include "ci/ciObjArray.hpp"
35 #include "ci/ciObjArrayKlass.hpp"
36 #include "ci/ciObject.hpp"
37 #include "ci/ciObjectFactory.hpp"
38 #include "ci/ciReplay.hpp"
39 #include "ci/ciSymbol.hpp"
40 #include "ci/ciSymbols.hpp"
41 #include "ci/ciTypeArray.hpp"
42 #include "ci/ciTypeArrayKlass.hpp"
43 #include "ci/ciUtilities.inline.hpp"
44 #include "classfile/javaClasses.inline.hpp"
45 #include "classfile/vmClasses.hpp"
347 EXCEPTION_CONTEXT;
348
349 if (o->is_instance()) {
350 instanceHandle h_i(THREAD, (instanceOop)o);
351 if (java_lang_invoke_CallSite::is_instance(o))
352 return new (arena()) ciCallSite(h_i);
353 else if (java_lang_invoke_MemberName::is_instance(o))
354 return new (arena()) ciMemberName(h_i);
355 else if (java_lang_invoke_MethodHandle::is_instance(o))
356 return new (arena()) ciMethodHandle(h_i);
357 else if (java_lang_invoke_MethodType::is_instance(o))
358 return new (arena()) ciMethodType(h_i);
359 else
360 return new (arena()) ciInstance(h_i);
361 } else if (o->is_objArray()) {
362 objArrayHandle h_oa(THREAD, (objArrayOop)o);
363 return new (arena()) ciObjArray(h_oa);
364 } else if (o->is_typeArray()) {
365 typeArrayHandle h_ta(THREAD, (typeArrayOop)o);
366 return new (arena()) ciTypeArray(h_ta);
367 }
368
369 // The oop is of some type not supported by the compiler interface.
370 ShouldNotReachHere();
371 return nullptr;
372 }
373
374 // ------------------------------------------------------------------
375 // ciObjectFactory::create_new_metadata
376 //
377 // Create a new ciMetadata from a Metadata*.
378 //
379 // Implementation note: in order to keep Metadata live, an auxiliary ciObject
380 // is used, which points to it's holder.
381 ciMetadata* ciObjectFactory::create_new_metadata(Metadata* o) {
382 EXCEPTION_CONTEXT;
383
384 if (o->is_klass()) {
385 Klass* k = (Klass*)o;
386 if (k->is_instance_klass()) {
387 assert(!ReplayCompiles || ciReplay::no_replay_state() || !ciReplay::is_klass_unresolved((InstanceKlass*)k), "must be whitelisted for replay compilation");
388 return new (arena()) ciInstanceKlass(k);
389 } else if (k->is_objArray_klass()) {
390 return new (arena()) ciObjArrayKlass(k);
391 } else if (k->is_typeArray_klass()) {
392 return new (arena()) ciTypeArrayKlass(k);
393 }
394 } else if (o->is_method()) {
395 methodHandle h_m(THREAD, (Method*)o);
396 ciEnv *env = CURRENT_THREAD_ENV;
397 ciInstanceKlass* holder = env->get_instance_klass(h_m()->method_holder());
398 return new (arena()) ciMethod(h_m, holder);
399 } else if (o->is_methodData()) {
400 // Hold methodHandle alive - might not be necessary ???
401 methodHandle h_m(THREAD, ((MethodData*)o)->method());
402 return new (arena()) ciMethodData((MethodData*)o);
403 }
404
405 // The Metadata* is of some type not supported by the compiler interface.
406 ShouldNotReachHere();
407 return nullptr;
408 }
605
606 //------------------------------------------------------------------
607 // ciObjectFactory::get_return_address
608 //
609 // Get a ciReturnAddress for a specified bci.
610 ciReturnAddress* ciObjectFactory::get_return_address(int bci) {
611 for (int i = 0; i < _return_addresses.length(); i++) {
612 ciReturnAddress* entry = _return_addresses.at(i);
613 if (entry->bci() == bci) {
614 // We've found a match.
615 return entry;
616 }
617 }
618
619 ciReturnAddress* new_ret_addr = new (arena()) ciReturnAddress(bci);
620 init_ident_of(new_ret_addr);
621 _return_addresses.append(new_ret_addr);
622 return new_ret_addr;
623 }
624
625 // ------------------------------------------------------------------
626 // ciObjectFactory::init_ident_of
627 void ciObjectFactory::init_ident_of(ciBaseObject* obj) {
628 obj->set_ident(_next_ident++);
629 }
630
631 static ciObjectFactory::NonPermObject* emptyBucket = nullptr;
632
633 // ------------------------------------------------------------------
634 // ciObjectFactory::find_non_perm
635 //
636 // Use a small hash table, hashed on the klass of the key.
637 // If there is no entry in the cache corresponding to this oop, return
638 // the null tail of the bucket into which the oop should be inserted.
639 ciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(oop key) {
640 assert(Universe::heap()->is_in(key), "must be");
641 ciMetadata* klass = get_metadata(key->klass());
642 NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS];
643 for (NonPermObject* p; (p = (*bp)) != nullptr; bp = &p->next()) {
644 if (is_equal(p, key)) break;
|
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 *
23 */
24
25 #include "ci/ciCallSite.hpp"
26 #include "ci/ciFlatArray.hpp"
27 #include "ci/ciFlatArrayKlass.hpp"
28 #include "ci/ciInlineKlass.hpp"
29 #include "ci/ciInstance.hpp"
30 #include "ci/ciInstanceKlass.hpp"
31 #include "ci/ciMemberName.hpp"
32 #include "ci/ciMethod.hpp"
33 #include "ci/ciMethodData.hpp"
34 #include "ci/ciMethodHandle.hpp"
35 #include "ci/ciMethodType.hpp"
36 #include "ci/ciNullObject.hpp"
37 #include "ci/ciObjArray.hpp"
38 #include "ci/ciObjArrayKlass.hpp"
39 #include "ci/ciObject.hpp"
40 #include "ci/ciObjectFactory.hpp"
41 #include "ci/ciReplay.hpp"
42 #include "ci/ciSymbol.hpp"
43 #include "ci/ciSymbols.hpp"
44 #include "ci/ciTypeArray.hpp"
45 #include "ci/ciTypeArrayKlass.hpp"
46 #include "ci/ciUtilities.inline.hpp"
47 #include "classfile/javaClasses.inline.hpp"
48 #include "classfile/vmClasses.hpp"
350 EXCEPTION_CONTEXT;
351
352 if (o->is_instance()) {
353 instanceHandle h_i(THREAD, (instanceOop)o);
354 if (java_lang_invoke_CallSite::is_instance(o))
355 return new (arena()) ciCallSite(h_i);
356 else if (java_lang_invoke_MemberName::is_instance(o))
357 return new (arena()) ciMemberName(h_i);
358 else if (java_lang_invoke_MethodHandle::is_instance(o))
359 return new (arena()) ciMethodHandle(h_i);
360 else if (java_lang_invoke_MethodType::is_instance(o))
361 return new (arena()) ciMethodType(h_i);
362 else
363 return new (arena()) ciInstance(h_i);
364 } else if (o->is_objArray()) {
365 objArrayHandle h_oa(THREAD, (objArrayOop)o);
366 return new (arena()) ciObjArray(h_oa);
367 } else if (o->is_typeArray()) {
368 typeArrayHandle h_ta(THREAD, (typeArrayOop)o);
369 return new (arena()) ciTypeArray(h_ta);
370 } else if (o->is_flatArray()) {
371 flatArrayHandle h_ta(THREAD, (flatArrayOop)o);
372 return new (arena()) ciFlatArray(h_ta);
373 }
374
375 // The oop is of some type not supported by the compiler interface.
376 ShouldNotReachHere();
377 return nullptr;
378 }
379
380 // ------------------------------------------------------------------
381 // ciObjectFactory::create_new_metadata
382 //
383 // Create a new ciMetadata from a Metadata*.
384 //
385 // Implementation note: in order to keep Metadata live, an auxiliary ciObject
386 // is used, which points to it's holder.
387 ciMetadata* ciObjectFactory::create_new_metadata(Metadata* o) {
388 EXCEPTION_CONTEXT;
389
390 if (o->is_klass()) {
391 Klass* k = (Klass*)o;
392 if (k->is_inline_klass()) {
393 return new (arena()) ciInlineKlass(k);
394 } else if (k->is_instance_klass()) {
395 assert(!ReplayCompiles || ciReplay::no_replay_state() || !ciReplay::is_klass_unresolved((InstanceKlass*)k), "must be whitelisted for replay compilation");
396 return new (arena()) ciInstanceKlass(k);
397 } else if (k->is_flatArray_klass()) {
398 return new (arena()) ciFlatArrayKlass(k);
399 } else if (k->is_objArray_klass()) {
400 return new (arena()) ciObjArrayKlass(k);
401 } else if (k->is_typeArray_klass()) {
402 return new (arena()) ciTypeArrayKlass(k);
403 }
404 } else if (o->is_method()) {
405 methodHandle h_m(THREAD, (Method*)o);
406 ciEnv *env = CURRENT_THREAD_ENV;
407 ciInstanceKlass* holder = env->get_instance_klass(h_m()->method_holder());
408 return new (arena()) ciMethod(h_m, holder);
409 } else if (o->is_methodData()) {
410 // Hold methodHandle alive - might not be necessary ???
411 methodHandle h_m(THREAD, ((MethodData*)o)->method());
412 return new (arena()) ciMethodData((MethodData*)o);
413 }
414
415 // The Metadata* is of some type not supported by the compiler interface.
416 ShouldNotReachHere();
417 return nullptr;
418 }
615
616 //------------------------------------------------------------------
617 // ciObjectFactory::get_return_address
618 //
619 // Get a ciReturnAddress for a specified bci.
620 ciReturnAddress* ciObjectFactory::get_return_address(int bci) {
621 for (int i = 0; i < _return_addresses.length(); i++) {
622 ciReturnAddress* entry = _return_addresses.at(i);
623 if (entry->bci() == bci) {
624 // We've found a match.
625 return entry;
626 }
627 }
628
629 ciReturnAddress* new_ret_addr = new (arena()) ciReturnAddress(bci);
630 init_ident_of(new_ret_addr);
631 _return_addresses.append(new_ret_addr);
632 return new_ret_addr;
633 }
634
635 ciWrapper* ciObjectFactory::make_null_free_wrapper(ciType* type) {
636 ciWrapper* wrapper = new (arena()) ciWrapper(type);
637 init_ident_of(wrapper);
638 return wrapper;
639 }
640
641 // ------------------------------------------------------------------
642 // ciObjectFactory::init_ident_of
643 void ciObjectFactory::init_ident_of(ciBaseObject* obj) {
644 obj->set_ident(_next_ident++);
645 }
646
647 static ciObjectFactory::NonPermObject* emptyBucket = nullptr;
648
649 // ------------------------------------------------------------------
650 // ciObjectFactory::find_non_perm
651 //
652 // Use a small hash table, hashed on the klass of the key.
653 // If there is no entry in the cache corresponding to this oop, return
654 // the null tail of the bucket into which the oop should be inserted.
655 ciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(oop key) {
656 assert(Universe::heap()->is_in(key), "must be");
657 ciMetadata* klass = get_metadata(key->klass());
658 NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS];
659 for (NonPermObject* p; (p = (*bp)) != nullptr; bp = &p->next()) {
660 if (is_equal(p, key)) break;
|