1 /*
2 * Copyright (c) 2012, 2016, 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 *
750 // sets up a set of methods with the same exact erased signature
751 FindMethodsByErasedSig visitor(slot->name(), slot->signature());
752 visitor.run(klass);
753
754 MethodFamily* family;
755 visitor.get_discovered_family(&family);
756 if (family != NULL) {
757 family->determine_target(klass, CHECK);
758 slot->bind_family(family);
759 }
760 }
761
762 static void merge_in_new_methods(InstanceKlass* klass,
763 GrowableArray<Method*>* new_methods, TRAPS);
764 static void create_default_methods( InstanceKlass* klass,
765 GrowableArray<Method*>* new_methods, TRAPS);
766
767 // This is the guts of the default methods implementation. This is called just
768 // after the classfile has been parsed if some ancestor has default methods.
769 //
770 // First if finds any name/signature slots that need any implementation (either
771 // because they are miranda or a superclass's implementation is an overpass
772 // itself). For each slot, iterate over the hierarchy, to see if they contain a
773 // signature that matches the slot we are looking at.
774 //
775 // For each slot filled, we generate an overpass method that either calls the
776 // unique default method candidate using invokespecial, or throws an exception
777 // (in the case of no default method candidates, or more than one valid
778 // candidate). These methods are then added to the class's method list.
779 // The JVM does not create bridges nor handle generic signatures here.
780 void DefaultMethods::generate_default_methods(
781 InstanceKlass* klass, const GrowableArray<Method*>* mirandas, TRAPS) {
782 assert(klass != NULL, "invariant");
783
784 // This resource mark is the bound for all memory allocation that takes
785 // place during default method processing. After this goes out of scope,
786 // all (Resource) objects' memory will be reclaimed. Be careful if adding an
787 // embedded resource mark under here as that memory can't be used outside
788 // whatever scope it's in.
789 ResourceMark rm(THREAD);
790
791 // Keep entire hierarchy alive for the duration of the computation
792 constantPoolHandle cp(THREAD, klass->constants());
793 KeepAliveRegistrar keepAlive(THREAD);
794 KeepAliveVisitor loadKeepAlive(&keepAlive);
795 loadKeepAlive.run(klass);
796
797 LogTarget(Debug, defaultmethods) lt;
798 if (lt.is_enabled()) {
884 klass->set_constants(cp);
885 cp->set_pool_holder(klass);
886
887 for (int i = 0; i < new_methods->length(); ++i) {
888 new_methods->at(i)->set_constants(cp);
889 }
890 for (int i = 0; i < klass->methods()->length(); ++i) {
891 Method* mo = klass->methods()->at(i);
892 mo->set_constants(cp);
893 }
894 }
895 }
896 }
897
898 // Create default_methods list for the current class.
899 // With the VM only processing erased signatures, the VM only
900 // creates an overpass in a conflict case or a case with no candidates.
901 // This allows virtual methods to override the overpass, but ensures
902 // that a local method search will find the exception rather than an abstract
903 // or default method that is not a valid candidate.
904 static void create_defaults_and_exceptions(
905 GrowableArray<EmptyVtableSlot*>* slots,
906 InstanceKlass* klass, TRAPS) {
907
908 GrowableArray<Method*> overpasses;
909 GrowableArray<Method*> defaults;
910 BytecodeConstantPool bpool(klass->constants());
911
912 for (int i = 0; i < slots->length(); ++i) {
913 EmptyVtableSlot* slot = slots->at(i);
914
915 if (slot->is_bound()) {
916 MethodFamily* method = slot->get_binding();
917 BytecodeBuffer buffer;
918
919 LogTarget(Debug, defaultmethods) lt;
920 if (lt.is_enabled()) {
921 ResourceMark rm(THREAD);
922 LogStream ls(lt);
923 ls.print("for slot: ");
|
1 /*
2 * Copyright (c) 2012, 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 *
750 // sets up a set of methods with the same exact erased signature
751 FindMethodsByErasedSig visitor(slot->name(), slot->signature());
752 visitor.run(klass);
753
754 MethodFamily* family;
755 visitor.get_discovered_family(&family);
756 if (family != NULL) {
757 family->determine_target(klass, CHECK);
758 slot->bind_family(family);
759 }
760 }
761
762 static void merge_in_new_methods(InstanceKlass* klass,
763 GrowableArray<Method*>* new_methods, TRAPS);
764 static void create_default_methods( InstanceKlass* klass,
765 GrowableArray<Method*>* new_methods, TRAPS);
766
767 // This is the guts of the default methods implementation. This is called just
768 // after the classfile has been parsed if some ancestor has default methods.
769 //
770 // First it finds any name/signature slots that need any implementation (either
771 // because they are miranda or a superclass's implementation is an overpass
772 // itself). For each slot, iterate over the hierarchy, to see if they contain a
773 // signature that matches the slot we are looking at.
774 //
775 // For each slot filled, we either record the default method candidate in the
776 // klass default_methods list or, only to handle exception cases, we create an
777 // overpass method that throws an exception and add it to the klass methods list.
778 // The JVM does not create bridges nor handle generic signatures here.
779 void DefaultMethods::generate_default_methods(
780 InstanceKlass* klass, const GrowableArray<Method*>* mirandas, TRAPS) {
781 assert(klass != NULL, "invariant");
782
783 // This resource mark is the bound for all memory allocation that takes
784 // place during default method processing. After this goes out of scope,
785 // all (Resource) objects' memory will be reclaimed. Be careful if adding an
786 // embedded resource mark under here as that memory can't be used outside
787 // whatever scope it's in.
788 ResourceMark rm(THREAD);
789
790 // Keep entire hierarchy alive for the duration of the computation
791 constantPoolHandle cp(THREAD, klass->constants());
792 KeepAliveRegistrar keepAlive(THREAD);
793 KeepAliveVisitor loadKeepAlive(&keepAlive);
794 loadKeepAlive.run(klass);
795
796 LogTarget(Debug, defaultmethods) lt;
797 if (lt.is_enabled()) {
883 klass->set_constants(cp);
884 cp->set_pool_holder(klass);
885
886 for (int i = 0; i < new_methods->length(); ++i) {
887 new_methods->at(i)->set_constants(cp);
888 }
889 for (int i = 0; i < klass->methods()->length(); ++i) {
890 Method* mo = klass->methods()->at(i);
891 mo->set_constants(cp);
892 }
893 }
894 }
895 }
896
897 // Create default_methods list for the current class.
898 // With the VM only processing erased signatures, the VM only
899 // creates an overpass in a conflict case or a case with no candidates.
900 // This allows virtual methods to override the overpass, but ensures
901 // that a local method search will find the exception rather than an abstract
902 // or default method that is not a valid candidate.
903 //
904 // Note that if overpass method are ever created that are not exception
905 // throwing methods then the loader constraint checking logic for vtable and
906 // itable creation needs to be changed to check loader constraints for the
907 // overpass methods that do not throw exceptions.
908 static void create_defaults_and_exceptions(
909 GrowableArray<EmptyVtableSlot*>* slots,
910 InstanceKlass* klass, TRAPS) {
911
912 GrowableArray<Method*> overpasses;
913 GrowableArray<Method*> defaults;
914 BytecodeConstantPool bpool(klass->constants());
915
916 for (int i = 0; i < slots->length(); ++i) {
917 EmptyVtableSlot* slot = slots->at(i);
918
919 if (slot->is_bound()) {
920 MethodFamily* method = slot->get_binding();
921 BytecodeBuffer buffer;
922
923 LogTarget(Debug, defaultmethods) lt;
924 if (lt.is_enabled()) {
925 ResourceMark rm(THREAD);
926 LogStream ls(lt);
927 ls.print("for slot: ");
|