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 "precompiled.hpp"
26 #include "jvm.h"
27 #include "classfile/systemDictionary.hpp"
28 #include "classfile/vmSymbols.hpp"
29 #include "interpreter/linkResolver.hpp"
30 #include "logging/log.hpp"
31 #include "logging/logStream.hpp"
32 #include "memory/metaspaceShared.hpp"
33 #include "memory/resourceArea.hpp"
34 #include "memory/universe.hpp"
35 #include "oops/instanceKlass.hpp"
36 #include "oops/klassVtable.hpp"
37 #include "oops/method.hpp"
38 #include "oops/objArrayOop.hpp"
39 #include "oops/oop.inline.hpp"
40 #include "runtime/arguments.hpp"
41 #include "runtime/handles.inline.hpp"
42 #include "runtime/safepointVerifiers.hpp"
43 #include "utilities/copy.hpp"
44
45 inline InstanceKlass* klassVtable::ik() const {
46 return InstanceKlass::cast(_klass);
488
489 // Do not check loader constraints for overpass methods because overpass
490 // methods are created by the jvm to throw exceptions.
491 if (checkconstraints && !target_method()->is_overpass()) {
492 // Override vtable entry if passes loader constraint check
493 // if loader constraint checking requested
494 // No need to visit his super, since he and his super
495 // have already made any needed loader constraints.
496 // Since loader constraints are transitive, it is enough
497 // to link to the first super, and we get all the others.
498 Handle super_loader(THREAD, super_klass->class_loader());
499
500 if (!oopDesc::equals(target_loader(), super_loader())) {
501 ResourceMark rm(THREAD);
502 Symbol* failed_type_symbol =
503 SystemDictionary::check_signature_loaders(signature, target_loader,
504 super_loader, true,
505 CHECK_(false));
506 if (failed_type_symbol != NULL) {
507 const char* msg = "loader constraint violation for class %s: when selecting "
508 "overriding method \"%s\" the class loader (instance of %s) of the "
509 "selected method's type %s, and the class loader (instance of %s) for its super "
510 "type %s have different Class objects for the type %s used in the signature";
511 char* curr_class = klass->name()->as_C_string();
512 char* sig = target_method()->name_and_sig_as_C_string();
513 const char* loader1 = SystemDictionary::loader_name(target_loader());
514 char* sel_class = target_klass->name()->as_C_string();
515 const char* loader2 = SystemDictionary::loader_name(super_loader());
516 char* super_class = super_klass->name()->as_C_string();
517 char* failed_type_name = failed_type_symbol->as_C_string();
518 size_t buflen = strlen(msg) + strlen(curr_class) + strlen(sig) +
519 strlen(loader1) + strlen(sel_class) + strlen(loader2) +
520 strlen(super_class) + strlen(failed_type_name);
521 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
522 jio_snprintf(buf, buflen, msg, curr_class, sig, loader1, sel_class, loader2,
523 super_class, failed_type_name);
524 THROW_MSG_(vmSymbols::java_lang_LinkageError(), buf, false);
525 }
526 }
527 }
528
529 put_method_at(target_method(), i);
530 overrides = true;
531 if (!is_default) {
532 target_method()->set_vtable_index(i);
533 } else {
534 if (def_vtable_indices != NULL) {
535 if (is_preinitialized_vtable()) {
536 // At runtime initialize_vtable is rerun as part of link_class_impl()
537 // for a shared class loaded by the non-boot loader.
538 // The dumptime vtable index should be the same as the runtime index.
539 assert(def_vtable_indices->at(default_index) == i,
540 "dump time vtable index is different from runtime index");
541 } else {
542 def_vtable_indices->at_put(default_index, i);
1218 // Entry does not resolve. Leave it empty for AbstractMethodError or other error.
1219 if (!(target == NULL) && !target->is_public()) {
1220 // Stuff an IllegalAccessError throwing method in there instead.
1221 itableOffsetEntry::method_entry(_klass, method_table_offset)[m->itable_index()].
1222 initialize(Universe::throw_illegal_access_error());
1223 }
1224 } else {
1225 // Entry did resolve, check loader constraints before initializing
1226 // if checkconstraints requested
1227 if (checkconstraints) {
1228 Handle method_holder_loader (THREAD, target->method_holder()->class_loader());
1229 if (!oopDesc::equals(method_holder_loader(), interface_loader())) {
1230 ResourceMark rm(THREAD);
1231 Symbol* failed_type_symbol =
1232 SystemDictionary::check_signature_loaders(m->signature(),
1233 method_holder_loader,
1234 interface_loader,
1235 true, CHECK);
1236 if (failed_type_symbol != NULL) {
1237 const char* msg = "loader constraint violation in interface itable"
1238 " initialization for class %s: when selecting method \"%s\" the"
1239 " class loader (instance of %s) for super interface %s, and the class"
1240 " loader (instance of %s) of the selected method's type, %s have"
1241 " different Class objects for the type %s used in the signature";
1242 char* current = _klass->name()->as_C_string();
1243 char* sig = m->name_and_sig_as_C_string();
1244 const char* loader1 = SystemDictionary::loader_name(interface_loader());
1245 char* iface = InstanceKlass::cast(interf)->name()->as_C_string();
1246 const char* loader2 = SystemDictionary::loader_name(method_holder_loader());
1247 char* mclass = target()->method_holder()->name()->as_C_string();
1248 char* failed_type_name = failed_type_symbol->as_C_string();
1249 size_t buflen = strlen(msg) + strlen(current) + strlen(sig) +
1250 strlen(loader1) + strlen(iface) + strlen(loader2) + strlen(mclass) +
1251 strlen(failed_type_name);
1252 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
1253 jio_snprintf(buf, buflen, msg, current, sig, loader1, iface,
1254 loader2, mclass, failed_type_name);
1255 THROW_MSG(vmSymbols::java_lang_LinkageError(), buf);
1256 }
1257 }
1258 }
1259
1260 // ime may have moved during GC so recalculate address
1261 int ime_num = m->itable_index();
1262 assert(ime_num < ime_count, "oob");
1263 itableOffsetEntry::method_entry(_klass, method_table_offset)[ime_num].initialize(target());
1264 if (log_develop_is_enabled(Trace, itables)) {
1265 ResourceMark rm(THREAD);
1266 if (target() != NULL) {
1267 LogTarget(Trace, itables) lt;
1268 LogStream ls(lt);
|
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 "precompiled.hpp"
26 #include "jvm.h"
27 #include "classfile/javaClasses.hpp"
28 #include "classfile/systemDictionary.hpp"
29 #include "classfile/vmSymbols.hpp"
30 #include "interpreter/linkResolver.hpp"
31 #include "logging/log.hpp"
32 #include "logging/logStream.hpp"
33 #include "memory/metaspaceShared.hpp"
34 #include "memory/resourceArea.hpp"
35 #include "memory/universe.hpp"
36 #include "oops/instanceKlass.hpp"
37 #include "oops/klassVtable.hpp"
38 #include "oops/method.hpp"
39 #include "oops/objArrayOop.hpp"
40 #include "oops/oop.inline.hpp"
41 #include "runtime/arguments.hpp"
42 #include "runtime/handles.inline.hpp"
43 #include "runtime/safepointVerifiers.hpp"
44 #include "utilities/copy.hpp"
45
46 inline InstanceKlass* klassVtable::ik() const {
47 return InstanceKlass::cast(_klass);
489
490 // Do not check loader constraints for overpass methods because overpass
491 // methods are created by the jvm to throw exceptions.
492 if (checkconstraints && !target_method()->is_overpass()) {
493 // Override vtable entry if passes loader constraint check
494 // if loader constraint checking requested
495 // No need to visit his super, since he and his super
496 // have already made any needed loader constraints.
497 // Since loader constraints are transitive, it is enough
498 // to link to the first super, and we get all the others.
499 Handle super_loader(THREAD, super_klass->class_loader());
500
501 if (!oopDesc::equals(target_loader(), super_loader())) {
502 ResourceMark rm(THREAD);
503 Symbol* failed_type_symbol =
504 SystemDictionary::check_signature_loaders(signature, target_loader,
505 super_loader, true,
506 CHECK_(false));
507 if (failed_type_symbol != NULL) {
508 const char* msg = "loader constraint violation for class %s: when selecting "
509 "overriding method %s the class loader %s of the "
510 "selected method's type %s, and the class loader %s for its super "
511 "type %s have different Class objects for the type %s used in the signature";
512 const char* curr_class = klass->external_name();
513 const char* method = target_method()->name_and_sig_as_C_string();
514 const char* loader1 = java_lang_ClassLoader::describe_external(target_loader());
515 const char* sel_class = target_klass->external_name();
516 const char* loader2 = java_lang_ClassLoader::describe_external(super_loader());
517 const char* super_class = super_klass->external_name();
518 const char* failed_type_name = failed_type_symbol->as_klass_external_name();
519 size_t buflen = strlen(msg) + strlen(curr_class) + strlen(method) +
520 strlen(loader1) + strlen(sel_class) + strlen(loader2) +
521 strlen(super_class) + strlen(failed_type_name);
522 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
523 jio_snprintf(buf, buflen, msg, curr_class, method, loader1, sel_class, loader2,
524 super_class, failed_type_name);
525 THROW_MSG_(vmSymbols::java_lang_LinkageError(), buf, false);
526 }
527 }
528 }
529
530 put_method_at(target_method(), i);
531 overrides = true;
532 if (!is_default) {
533 target_method()->set_vtable_index(i);
534 } else {
535 if (def_vtable_indices != NULL) {
536 if (is_preinitialized_vtable()) {
537 // At runtime initialize_vtable is rerun as part of link_class_impl()
538 // for a shared class loaded by the non-boot loader.
539 // The dumptime vtable index should be the same as the runtime index.
540 assert(def_vtable_indices->at(default_index) == i,
541 "dump time vtable index is different from runtime index");
542 } else {
543 def_vtable_indices->at_put(default_index, i);
1219 // Entry does not resolve. Leave it empty for AbstractMethodError or other error.
1220 if (!(target == NULL) && !target->is_public()) {
1221 // Stuff an IllegalAccessError throwing method in there instead.
1222 itableOffsetEntry::method_entry(_klass, method_table_offset)[m->itable_index()].
1223 initialize(Universe::throw_illegal_access_error());
1224 }
1225 } else {
1226 // Entry did resolve, check loader constraints before initializing
1227 // if checkconstraints requested
1228 if (checkconstraints) {
1229 Handle method_holder_loader (THREAD, target->method_holder()->class_loader());
1230 if (!oopDesc::equals(method_holder_loader(), interface_loader())) {
1231 ResourceMark rm(THREAD);
1232 Symbol* failed_type_symbol =
1233 SystemDictionary::check_signature_loaders(m->signature(),
1234 method_holder_loader,
1235 interface_loader,
1236 true, CHECK);
1237 if (failed_type_symbol != NULL) {
1238 const char* msg = "loader constraint violation in interface itable"
1239 " initialization for class %s: when selecting method %s the"
1240 " class loader %s for super interface %s, and the class"
1241 " loader %s of the selected method's type, %s have"
1242 " different Class objects for the type %s used in the signature";
1243 const char* current = _klass->external_name();
1244 const char* sig = m->name_and_sig_as_C_string();
1245 const char* loader1 = java_lang_ClassLoader::describe_external(interface_loader());
1246 const char* iface = InstanceKlass::cast(interf)->external_name();
1247 const char* loader2 = java_lang_ClassLoader::describe_external(method_holder_loader());
1248 const char* mclass = target()->method_holder()->external_name();
1249 const char* failed_type_name = failed_type_symbol->as_klass_external_name();
1250 size_t buflen = strlen(msg) + strlen(current) + strlen(sig) +
1251 strlen(loader1) + strlen(iface) + strlen(loader2) + strlen(mclass) +
1252 strlen(failed_type_name);
1253 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
1254 jio_snprintf(buf, buflen, msg, current, sig, loader1, iface,
1255 loader2, mclass, failed_type_name);
1256 THROW_MSG(vmSymbols::java_lang_LinkageError(), buf);
1257 }
1258 }
1259 }
1260
1261 // ime may have moved during GC so recalculate address
1262 int ime_num = m->itable_index();
1263 assert(ime_num < ime_count, "oob");
1264 itableOffsetEntry::method_entry(_klass, method_table_offset)[ime_num].initialize(target());
1265 if (log_develop_is_enabled(Trace, itables)) {
1266 ResourceMark rm(THREAD);
1267 if (target() != NULL) {
1268 LogTarget(Trace, itables) lt;
1269 LogStream ls(lt);
|