Mon, 27 Mar 2017 11:31:27 -0700
Merge
1.1 --- a/.hgtags Mon Mar 27 08:21:39 2017 -0700 1.2 +++ b/.hgtags Mon Mar 27 11:31:27 2017 -0700 1.3 @@ -945,6 +945,18 @@ 1.4 11f91811e4d7e5ddfaf938dcf386ec8fe5bf7b7c jdk8u121-b11 1.5 b132b08b28bf23a26329928cf6b4ffda5857f4d3 jdk8u121-b12 1.6 90f94521c3515e5f27af0ab9b31d036e88bb322a jdk8u121-b13 1.7 +c0a1ba0df20fda10ddb8599e888eb56ad98b3874 jdk8u131-b00 1.8 +0b85ccd6240991e1a501602ff5addec6b88ae0af jdk8u131-b01 1.9 +ef90c721a4e59b01ca36f25619010a1afe9ed4d5 jdk8u131-b02 1.10 +0ca47d0811b01ecf8651b6045a1e33a4a9bed0ee jdk8u131-b03 1.11 +dab1d597165207e14b6886b1823c1e990bc776a3 jdk8u131-b04 1.12 +c965fc1aa840a0903709ad69aa0e2100330ccd84 jdk8u131-b05 1.13 +6e4cfbc7534f83902692132efb61683528c04a59 jdk8u131-b06 1.14 +5b3cb4fbdbc7bdeb7c78a8703c3084ce068f6691 jdk8u131-b07 1.15 +db221c0a423e776bec5c3198d11d3f26827bd786 jdk8u131-b08 1.16 +56e71d16083904ceddfdd1d66312582a42781646 jdk8u131-b09 1.17 +1da23ae49386608550596502d90a381ee6c1dfaa jdk8u131-b10 1.18 +829ea9b92cda9545652f1b309f56c57383024ebb jdk8u131-b11 1.19 5aa8c4ca51f0e666d368a4f119ed734d3ac59d7c jdk8u122-b00 1.20 2198ef7e1c1702b3506b95b5d8c886ad5a12bbe5 jdk8u122-b01 1.21 58d961f47dd4ee1d516512b7744e0f1fc83d8f52 jdk8u122-b02
2.1 --- a/src/cpu/sparc/vm/c1_LIRGenerator_sparc.cpp Mon Mar 27 08:21:39 2017 -0700 2.2 +++ b/src/cpu/sparc/vm/c1_LIRGenerator_sparc.cpp Mon Mar 27 11:31:27 2017 -0700 2.3 @@ -1023,11 +1023,16 @@ 2.4 obj.load_item(); 2.5 LIR_Opr out_reg = rlock_result(x); 2.6 CodeStub* stub; 2.7 - CodeEmitInfo* info_for_exception = state_for(x); 2.8 + CodeEmitInfo* info_for_exception = 2.9 + (x->needs_exception_state() ? state_for(x) : 2.10 + state_for(x, x->state_before(), true /*ignore_xhandler*/)); 2.11 2.12 if (x->is_incompatible_class_change_check()) { 2.13 assert(patching_info == NULL, "can't patch this"); 2.14 stub = new SimpleExceptionStub(Runtime1::throw_incompatible_class_change_error_id, LIR_OprFact::illegalOpr, info_for_exception); 2.15 + } else if (x->is_invokespecial_receiver_check()) { 2.16 + assert(patching_info == NULL, "can't patch this"); 2.17 + stub = new DeoptimizeStub(info_for_exception); 2.18 } else { 2.19 stub = new SimpleExceptionStub(Runtime1::throw_class_cast_exception_id, obj.result(), info_for_exception); 2.20 }
3.1 --- a/src/cpu/x86/vm/c1_LIRGenerator_x86.cpp Mon Mar 27 08:21:39 2017 -0700 3.2 +++ b/src/cpu/x86/vm/c1_LIRGenerator_x86.cpp Mon Mar 27 11:31:27 2017 -0700 3.3 @@ -1228,12 +1228,17 @@ 3.4 obj.load_item(); 3.5 3.6 // info for exceptions 3.7 - CodeEmitInfo* info_for_exception = state_for(x); 3.8 + CodeEmitInfo* info_for_exception = 3.9 + (x->needs_exception_state() ? state_for(x) : 3.10 + state_for(x, x->state_before(), true /*ignore_xhandler*/)); 3.11 3.12 CodeStub* stub; 3.13 if (x->is_incompatible_class_change_check()) { 3.14 assert(patching_info == NULL, "can't patch this"); 3.15 stub = new SimpleExceptionStub(Runtime1::throw_incompatible_class_change_error_id, LIR_OprFact::illegalOpr, info_for_exception); 3.16 + } else if (x->is_invokespecial_receiver_check()) { 3.17 + assert(patching_info == NULL, "can't patch this"); 3.18 + stub = new DeoptimizeStub(info_for_exception); 3.19 } else { 3.20 stub = new SimpleExceptionStub(Runtime1::throw_class_cast_exception_id, obj.result(), info_for_exception); 3.21 }
4.1 --- a/src/share/vm/c1/c1_CodeStubs.hpp Mon Mar 27 08:21:39 2017 -0700 4.2 +++ b/src/share/vm/c1/c1_CodeStubs.hpp Mon Mar 27 11:31:27 2017 -0700 4.3 @@ -1,5 +1,5 @@ 4.4 /* 4.5 - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 4.6 + * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. 4.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.8 * 4.9 * This code is free software; you can redistribute it and/or modify it 4.10 @@ -57,6 +57,7 @@ 4.11 virtual bool is_exception_throw_stub() const { return false; } 4.12 virtual bool is_range_check_stub() const { return false; } 4.13 virtual bool is_divbyzero_stub() const { return false; } 4.14 + virtual bool is_simple_exception_stub() const { return false; } 4.15 #ifndef PRODUCT 4.16 virtual void print_name(outputStream* out) const = 0; 4.17 #endif 4.18 @@ -484,6 +485,7 @@ 4.19 virtual void emit_code(LIR_Assembler* e); 4.20 virtual CodeEmitInfo* info() const { return _info; } 4.21 virtual bool is_exception_throw_stub() const { return true; } 4.22 + virtual bool is_simple_exception_stub() const { return true; } 4.23 virtual void visit(LIR_OpVisitState* visitor) { 4.24 if (_obj->is_valid()) visitor->do_input(_obj); 4.25 visitor->do_slow_case(_info);
5.1 --- a/src/share/vm/c1/c1_GraphBuilder.cpp Mon Mar 27 08:21:39 2017 -0700 5.2 +++ b/src/share/vm/c1/c1_GraphBuilder.cpp Mon Mar 27 11:31:27 2017 -0700 5.3 @@ -1837,6 +1837,20 @@ 5.4 log->identify(target), 5.5 Bytecodes::name(code)); 5.6 5.7 + // invoke-special-super 5.8 + if (bc_raw == Bytecodes::_invokespecial && !target->is_object_initializer()) { 5.9 + ciInstanceKlass* sender_klass = 5.10 + calling_klass->is_anonymous() ? calling_klass->host_klass() : 5.11 + calling_klass; 5.12 + if (sender_klass->is_interface()) { 5.13 + int index = state()->stack_size() - (target->arg_size_no_receiver() + 1); 5.14 + Value receiver = state()->stack_at(index); 5.15 + CheckCast* c = new CheckCast(sender_klass, receiver, copy_state_before()); 5.16 + c->set_invokespecial_receiver_check(); 5.17 + state()->stack_at_put(index, append_split(c)); 5.18 + } 5.19 + } 5.20 + 5.21 // Some methods are obviously bindable without any type checks so 5.22 // convert them directly to an invokespecial or invokestatic. 5.23 if (target->is_loaded() && !target->is_abstract() && target->can_be_statically_bound()) {
6.1 --- a/src/share/vm/c1/c1_Instruction.hpp Mon Mar 27 08:21:39 2017 -0700 6.2 +++ b/src/share/vm/c1/c1_Instruction.hpp Mon Mar 27 11:31:27 2017 -0700 6.3 @@ -381,6 +381,7 @@ 6.4 UnorderedIsTrueFlag, 6.5 NeedsPatchingFlag, 6.6 ThrowIncompatibleClassChangeErrorFlag, 6.7 + InvokeSpecialReceiverCheckFlag, 6.8 ProfileMDOFlag, 6.9 IsLinkedInBlockFlag, 6.10 NeedsRangeCheckFlag, 6.11 @@ -1456,6 +1457,16 @@ 6.12 bool is_incompatible_class_change_check() const { 6.13 return check_flag(ThrowIncompatibleClassChangeErrorFlag); 6.14 } 6.15 + void set_invokespecial_receiver_check() { 6.16 + set_flag(InvokeSpecialReceiverCheckFlag, true); 6.17 + } 6.18 + bool is_invokespecial_receiver_check() const { 6.19 + return check_flag(InvokeSpecialReceiverCheckFlag); 6.20 + } 6.21 + 6.22 + virtual bool needs_exception_state() const { 6.23 + return !is_invokespecial_receiver_check(); 6.24 + } 6.25 6.26 ciType* declared_type() const; 6.27 };
7.1 --- a/src/share/vm/ci/ciInstanceKlass.cpp Mon Mar 27 08:21:39 2017 -0700 7.2 +++ b/src/share/vm/ci/ciInstanceKlass.cpp Mon Mar 27 11:31:27 2017 -0700 7.3 @@ -1,5 +1,5 @@ 7.4 /* 7.5 - * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. 7.6 + * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. 7.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.8 * 7.9 * This code is free software; you can redistribute it and/or modify it 7.10 @@ -58,6 +58,7 @@ 7.11 _nonstatic_field_size = ik->nonstatic_field_size(); 7.12 _has_nonstatic_fields = ik->has_nonstatic_fields(); 7.13 _has_default_methods = ik->has_default_methods(); 7.14 + _is_anonymous = ik->is_anonymous(); 7.15 _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields: 7.16 7.17 _implementor = NULL; // we will fill these lazily 7.18 @@ -100,6 +101,7 @@ 7.19 _nonstatic_field_size = -1; 7.20 _has_nonstatic_fields = false; 7.21 _nonstatic_fields = NULL; 7.22 + _is_anonymous = false; 7.23 _loader = loader; 7.24 _protection_domain = protection_domain; 7.25 _is_shared = false; 7.26 @@ -591,6 +593,16 @@ 7.27 return impl; 7.28 } 7.29 7.30 +ciInstanceKlass* ciInstanceKlass::host_klass() { 7.31 + assert(is_loaded(), "must be loaded"); 7.32 + if (is_anonymous()) { 7.33 + VM_ENTRY_MARK 7.34 + Klass* host_klass = get_instanceKlass()->host_klass(); 7.35 + return CURRENT_ENV->get_instance_klass(host_klass); 7.36 + } 7.37 + return NULL; 7.38 +} 7.39 + 7.40 // Utility class for printing of the contents of the static fields for 7.41 // use by compilation replay. It only prints out the information that 7.42 // could be consumed by the compiler, so for primitive types it prints
8.1 --- a/src/share/vm/ci/ciInstanceKlass.hpp Mon Mar 27 08:21:39 2017 -0700 8.2 +++ b/src/share/vm/ci/ciInstanceKlass.hpp Mon Mar 27 11:31:27 2017 -0700 8.3 @@ -1,5 +1,5 @@ 8.4 /* 8.5 - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 8.6 + * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. 8.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.8 * 8.9 * This code is free software; you can redistribute it and/or modify it 8.10 @@ -53,6 +53,7 @@ 8.11 bool _has_subklass; 8.12 bool _has_nonstatic_fields; 8.13 bool _has_default_methods; 8.14 + bool _is_anonymous; 8.15 8.16 ciFlags _flags; 8.17 jint _nonstatic_field_size; 8.18 @@ -177,6 +178,10 @@ 8.19 return _has_default_methods; 8.20 } 8.21 8.22 + bool is_anonymous() { 8.23 + return _is_anonymous; 8.24 + } 8.25 + 8.26 ciInstanceKlass* get_canonical_holder(int offset); 8.27 ciField* get_field_by_offset(int field_offset, bool is_static); 8.28 ciField* get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static); 8.29 @@ -248,6 +253,8 @@ 8.30 return NULL; 8.31 } 8.32 8.33 + ciInstanceKlass* host_klass(); 8.34 + 8.35 // Dump the current state of this klass for compilation replay. 8.36 virtual void dump_replay_data(outputStream* out); 8.37 };
9.1 --- a/src/share/vm/ci/ciMethod.cpp Mon Mar 27 08:21:39 2017 -0700 9.2 +++ b/src/share/vm/ci/ciMethod.cpp Mon Mar 27 11:31:27 2017 -0700 9.3 @@ -1,5 +1,5 @@ 9.4 /* 9.5 - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 9.6 + * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. 9.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9.8 * 9.9 * This code is free software; you can redistribute it and/or modify it 9.10 @@ -948,6 +948,13 @@ 9.11 } 9.12 9.13 // ------------------------------------------------------------------ 9.14 +// ciMethod::is_object_initializer 9.15 +// 9.16 +bool ciMethod::is_object_initializer() const { 9.17 + return name() == ciSymbol::object_initializer_name(); 9.18 +} 9.19 + 9.20 +// ------------------------------------------------------------------ 9.21 // ciMethod::has_member_arg 9.22 // 9.23 // Return true if the method is a linker intrinsic like _linkToVirtual.
10.1 --- a/src/share/vm/ci/ciMethod.hpp Mon Mar 27 08:21:39 2017 -0700 10.2 +++ b/src/share/vm/ci/ciMethod.hpp Mon Mar 27 11:31:27 2017 -0700 10.3 @@ -1,5 +1,5 @@ 10.4 /* 10.5 - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 10.6 + * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. 10.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 10.8 * 10.9 * This code is free software; you can redistribute it and/or modify it 10.10 @@ -331,6 +331,7 @@ 10.11 bool can_be_statically_bound() const { return _can_be_statically_bound; } 10.12 bool is_boxing_method() const; 10.13 bool is_unboxing_method() const; 10.14 + bool is_object_initializer() const; 10.15 10.16 // Replay data methods 10.17 void dump_name_as_ascii(outputStream* st);
11.1 --- a/src/share/vm/interpreter/interpreterRuntime.cpp Mon Mar 27 08:21:39 2017 -0700 11.2 +++ b/src/share/vm/interpreter/interpreterRuntime.cpp Mon Mar 27 11:31:27 2017 -0700 11.3 @@ -690,7 +690,8 @@ 11.4 IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode)) { 11.5 // extract receiver from the outgoing argument list if necessary 11.6 Handle receiver(thread, NULL); 11.7 - if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface) { 11.8 + if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface || 11.9 + bytecode == Bytecodes::_invokespecial) { 11.10 ResourceMark rm(thread); 11.11 methodHandle m (thread, method(thread)); 11.12 Bytecode_invoke call(m, bci(thread)); 11.13 @@ -756,16 +757,25 @@ 11.14 int index = info.resolved_method()->itable_index(); 11.15 assert(info.itable_index() == index, ""); 11.16 } 11.17 + } else if (bytecode == Bytecodes::_invokespecial) { 11.18 + assert(info.call_kind() == CallInfo::direct_call, "must be direct call"); 11.19 } else { 11.20 assert(info.call_kind() == CallInfo::direct_call || 11.21 info.call_kind() == CallInfo::vtable_call, ""); 11.22 } 11.23 #endif 11.24 + // Get sender or sender's host_klass, and only set cpCache entry to resolved if 11.25 + // it is not an interface. The receiver for invokespecial calls within interface 11.26 + // methods must be checked for every call. 11.27 + InstanceKlass* sender = pool->pool_holder(); 11.28 + sender = sender->is_anonymous() ? InstanceKlass::cast(sender->host_klass()) : sender; 11.29 + 11.30 switch (info.call_kind()) { 11.31 case CallInfo::direct_call: 11.32 cache_entry(thread)->set_direct_call( 11.33 bytecode, 11.34 - info.resolved_method()); 11.35 + info.resolved_method(), 11.36 + sender->is_interface()); 11.37 break; 11.38 case CallInfo::vtable_call: 11.39 cache_entry(thread)->set_vtable_call(
12.1 --- a/src/share/vm/interpreter/linkResolver.cpp Mon Mar 27 08:21:39 2017 -0700 12.2 +++ b/src/share/vm/interpreter/linkResolver.cpp Mon Mar 27 11:31:27 2017 -0700 12.3 @@ -915,11 +915,11 @@ 12.4 } 12.5 12.6 12.7 -void LinkResolver::resolve_special_call(CallInfo& result, KlassHandle resolved_klass, Symbol* method_name, 12.8 +void LinkResolver::resolve_special_call(CallInfo& result, Handle recv, KlassHandle resolved_klass, Symbol* method_name, 12.9 Symbol* method_signature, KlassHandle current_klass, bool check_access, TRAPS) { 12.10 methodHandle resolved_method; 12.11 linktime_resolve_special_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); 12.12 - runtime_resolve_special_method(result, resolved_method, resolved_klass, current_klass, check_access, CHECK); 12.13 + runtime_resolve_special_method(result, resolved_method, resolved_klass, current_klass, recv, check_access, CHECK); 12.14 } 12.15 12.16 // throws linktime exceptions 12.17 @@ -1018,7 +1018,7 @@ 12.18 12.19 // throws runtime exceptions 12.20 void LinkResolver::runtime_resolve_special_method(CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, 12.21 - KlassHandle current_klass, bool check_access, TRAPS) { 12.22 + KlassHandle current_klass, Handle recv, bool check_access, TRAPS) { 12.23 12.24 // resolved method is selected method unless we have an old-style lookup 12.25 // for a superclass method 12.26 @@ -1026,21 +1026,19 @@ 12.27 // no checks for shadowing 12.28 methodHandle sel_method(THREAD, resolved_method()); 12.29 12.30 + if (check_access && 12.31 + // check if the method is not <init> 12.32 + resolved_method->name() != vmSymbols::object_initializer_name()) { 12.33 + 12.34 // check if this is an old-style super call and do a new lookup if so 12.35 - { KlassHandle method_klass = KlassHandle(THREAD, 12.36 - resolved_method->method_holder()); 12.37 - 12.38 - if (check_access && 12.39 // a) check if ACC_SUPER flag is set for the current class 12.40 - (current_klass->is_super() || !AllowNonVirtualCalls) && 12.41 + if ((current_klass->is_super() || !AllowNonVirtualCalls) && 12.42 // b) check if the class of the resolved_klass is a superclass 12.43 // (not supertype in order to exclude interface classes) of the current class. 12.44 // This check is not performed for super.invoke for interface methods 12.45 // in super interfaces. 12.46 current_klass->is_subclass_of(resolved_klass()) && 12.47 - current_klass() != resolved_klass() && 12.48 - // c) check if the method is not <init> 12.49 - resolved_method->name() != vmSymbols::object_initializer_name()) { 12.50 + current_klass() != resolved_klass()) { 12.51 // Lookup super method 12.52 KlassHandle super_klass(THREAD, current_klass->super()); 12.53 lookup_instance_method_in_klasses(sel_method, super_klass, 12.54 @@ -1055,6 +1053,27 @@ 12.55 resolved_method->signature())); 12.56 } 12.57 } 12.58 + 12.59 + // Check that the class of objectref (the receiver) is the current class or interface, 12.60 + // or a subtype of the current class or interface (the sender), otherwise invokespecial 12.61 + // throws IllegalAccessError. 12.62 + // The verifier checks that the sender is a subtype of the class in the I/MR operand. 12.63 + // The verifier also checks that the receiver is a subtype of the sender, if the sender is 12.64 + // a class. If the sender is an interface, the check has to be performed at runtime. 12.65 + InstanceKlass* sender = InstanceKlass::cast(current_klass()); 12.66 + sender = sender->is_anonymous() ? InstanceKlass::cast(sender->host_klass()) : sender; 12.67 + if (sender->is_interface() && recv.not_null()) { 12.68 + Klass* receiver_klass = recv->klass(); 12.69 + if (!receiver_klass->is_subtype_of(sender)) { 12.70 + ResourceMark rm(THREAD); 12.71 + char buf[500]; 12.72 + jio_snprintf(buf, sizeof(buf), 12.73 + "Receiver class %s must be the current class or a subtype of interface %s", 12.74 + receiver_klass->name()->as_C_string(), 12.75 + sender->name()->as_C_string()); 12.76 + THROW_MSG(vmSymbols::java_lang_IllegalAccessError(), buf); 12.77 + } 12.78 + } 12.79 } 12.80 12.81 // check if not static 12.82 @@ -1481,7 +1500,7 @@ 12.83 bool check_access) { 12.84 EXCEPTION_MARK; 12.85 CallInfo info; 12.86 - resolve_special_call(info, resolved_klass, name, signature, current_klass, check_access, THREAD); 12.87 + resolve_special_call(info, Handle(), resolved_klass, name, signature, current_klass, check_access, THREAD); 12.88 if (HAS_PENDING_EXCEPTION) { 12.89 CLEAR_PENDING_EXCEPTION; 12.90 return methodHandle(); 12.91 @@ -1497,7 +1516,7 @@ 12.92 void LinkResolver::resolve_invoke(CallInfo& result, Handle recv, constantPoolHandle pool, int index, Bytecodes::Code byte, TRAPS) { 12.93 switch (byte) { 12.94 case Bytecodes::_invokestatic : resolve_invokestatic (result, pool, index, CHECK); break; 12.95 - case Bytecodes::_invokespecial : resolve_invokespecial (result, pool, index, CHECK); break; 12.96 + case Bytecodes::_invokespecial : resolve_invokespecial (result, recv, pool, index, CHECK); break; 12.97 case Bytecodes::_invokevirtual : resolve_invokevirtual (result, recv, pool, index, CHECK); break; 12.98 case Bytecodes::_invokehandle : resolve_invokehandle (result, pool, index, CHECK); break; 12.99 case Bytecodes::_invokedynamic : resolve_invokedynamic (result, pool, index, CHECK); break; 12.100 @@ -1528,13 +1547,13 @@ 12.101 } 12.102 12.103 12.104 -void LinkResolver::resolve_invokespecial(CallInfo& result, constantPoolHandle pool, int index, TRAPS) { 12.105 +void LinkResolver::resolve_invokespecial(CallInfo& result, Handle recv, constantPoolHandle pool, int index, TRAPS) { 12.106 KlassHandle resolved_klass; 12.107 Symbol* method_name = NULL; 12.108 Symbol* method_signature = NULL; 12.109 KlassHandle current_klass; 12.110 resolve_pool(resolved_klass, method_name, method_signature, current_klass, pool, index, CHECK); 12.111 - resolve_special_call(result, resolved_klass, method_name, method_signature, current_klass, true, CHECK); 12.112 + resolve_special_call(result, recv, resolved_klass, method_name, method_signature, current_klass, true, CHECK); 12.113 } 12.114 12.115
13.1 --- a/src/share/vm/interpreter/linkResolver.hpp Mon Mar 27 08:21:39 2017 -0700 13.2 +++ b/src/share/vm/interpreter/linkResolver.hpp Mon Mar 27 11:31:27 2017 -0700 13.3 @@ -1,5 +1,5 @@ 13.4 /* 13.5 - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 13.6 + * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. 13.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 13.8 * 13.9 * This code is free software; you can redistribute it and/or modify it 13.10 @@ -142,7 +142,7 @@ 13.11 static void linktime_resolve_virtual_method (methodHandle &resolved_method, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature,KlassHandle current_klass, bool check_access, TRAPS); 13.12 static void linktime_resolve_interface_method (methodHandle& resolved_method, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access, TRAPS); 13.13 13.14 - static void runtime_resolve_special_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, KlassHandle current_klass, bool check_access, TRAPS); 13.15 + static void runtime_resolve_special_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, KlassHandle current_klass, Handle recv, bool check_access, TRAPS); 13.16 static void runtime_resolve_virtual_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, Handle recv, KlassHandle recv_klass, bool check_null_and_abstract, TRAPS); 13.17 static void runtime_resolve_interface_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, Handle recv, KlassHandle recv_klass, bool check_null_and_abstract, TRAPS); 13.18 13.19 @@ -173,7 +173,7 @@ 13.20 // resolved_klass = specified class (i.e., static receiver class) 13.21 // current_klass = sending method holder (i.e., class containing the method containing the call being resolved) 13.22 static void resolve_static_call (CallInfo& result, KlassHandle& resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access, bool initialize_klass, TRAPS); 13.23 - static void resolve_special_call (CallInfo& result, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access, TRAPS); 13.24 + static void resolve_special_call (CallInfo& result, Handle recv, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access, TRAPS); 13.25 static void resolve_virtual_call (CallInfo& result, Handle recv, KlassHandle recv_klass, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access, bool check_null_and_abstract, TRAPS); 13.26 static void resolve_interface_call(CallInfo& result, Handle recv, KlassHandle recv_klass, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, bool check_access, bool check_null_and_abstract, TRAPS); 13.27 static void resolve_handle_call (CallInfo& result, KlassHandle resolved_klass, Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, TRAPS); 13.28 @@ -196,7 +196,7 @@ 13.29 13.30 // runtime resolving from constant pool 13.31 static void resolve_invokestatic (CallInfo& result, constantPoolHandle pool, int index, TRAPS); 13.32 - static void resolve_invokespecial (CallInfo& result, constantPoolHandle pool, int index, TRAPS); 13.33 + static void resolve_invokespecial (CallInfo& result, Handle recv, constantPoolHandle pool, int index, TRAPS); 13.34 static void resolve_invokevirtual (CallInfo& result, Handle recv, constantPoolHandle pool, int index, TRAPS); 13.35 static void resolve_invokeinterface(CallInfo& result, Handle recv, constantPoolHandle pool, int index, TRAPS); 13.36 static void resolve_invokedynamic (CallInfo& result, constantPoolHandle pool, int index, TRAPS);
14.1 --- a/src/share/vm/oops/cpCache.cpp Mon Mar 27 08:21:39 2017 -0700 14.2 +++ b/src/share/vm/oops/cpCache.cpp Mon Mar 27 11:31:27 2017 -0700 14.3 @@ -1,5 +1,5 @@ 14.4 /* 14.5 - * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved. 14.6 + * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved. 14.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 14.8 * 14.9 * This code is free software; you can redistribute it and/or modify it 14.10 @@ -144,7 +144,8 @@ 14.11 14.12 void ConstantPoolCacheEntry::set_direct_or_vtable_call(Bytecodes::Code invoke_code, 14.13 methodHandle method, 14.14 - int vtable_index) { 14.15 + int vtable_index, 14.16 + bool sender_is_interface) { 14.17 bool is_vtable_call = (vtable_index >= 0); // FIXME: split this method on this boolean 14.18 assert(method->interpreter_entry() != NULL, "should have been set at this point"); 14.19 assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache"); 14.20 @@ -208,7 +209,13 @@ 14.21 if (byte_no == 1) { 14.22 assert(invoke_code != Bytecodes::_invokevirtual && 14.23 invoke_code != Bytecodes::_invokeinterface, ""); 14.24 + // Don't mark invokespecial to method as resolved if sender is an interface. The receiver 14.25 + // has to be checked that it is a subclass of the current class every time this bytecode 14.26 + // is executed. 14.27 + if (invoke_code != Bytecodes::_invokespecial || !sender_is_interface || 14.28 + method->name() == vmSymbols::object_initializer_name()) { 14.29 set_bytecode_1(invoke_code); 14.30 + } 14.31 } else if (byte_no == 2) { 14.32 if (change_to_virtual) { 14.33 assert(invoke_code == Bytecodes::_invokeinterface, ""); 14.34 @@ -238,17 +245,18 @@ 14.35 NOT_PRODUCT(verify(tty)); 14.36 } 14.37 14.38 -void ConstantPoolCacheEntry::set_direct_call(Bytecodes::Code invoke_code, methodHandle method) { 14.39 +void ConstantPoolCacheEntry::set_direct_call(Bytecodes::Code invoke_code, methodHandle method, 14.40 + bool sender_is_interface) { 14.41 int index = Method::nonvirtual_vtable_index; 14.42 // index < 0; FIXME: inline and customize set_direct_or_vtable_call 14.43 - set_direct_or_vtable_call(invoke_code, method, index); 14.44 + set_direct_or_vtable_call(invoke_code, method, index, sender_is_interface); 14.45 } 14.46 14.47 void ConstantPoolCacheEntry::set_vtable_call(Bytecodes::Code invoke_code, methodHandle method, int index) { 14.48 // either the method is a miranda or its holder should accept the given index 14.49 assert(method->method_holder()->is_interface() || method->method_holder()->verify_vtable_index(index), ""); 14.50 // index >= 0; FIXME: inline and customize set_direct_or_vtable_call 14.51 - set_direct_or_vtable_call(invoke_code, method, index); 14.52 + set_direct_or_vtable_call(invoke_code, method, index, false); 14.53 } 14.54 14.55 void ConstantPoolCacheEntry::set_itable_call(Bytecodes::Code invoke_code, methodHandle method, int index) {
15.1 --- a/src/share/vm/oops/cpCache.hpp Mon Mar 27 08:21:39 2017 -0700 15.2 +++ b/src/share/vm/oops/cpCache.hpp Mon Mar 27 11:31:27 2017 -0700 15.3 @@ -229,13 +229,15 @@ 15.4 void set_direct_or_vtable_call( 15.5 Bytecodes::Code invoke_code, // the bytecode used for invoking the method 15.6 methodHandle method, // the method/prototype if any (NULL, otherwise) 15.7 - int vtable_index // the vtable index if any, else negative 15.8 + int vtable_index, // the vtable index if any, else negative 15.9 + bool sender_is_interface 15.10 ); 15.11 15.12 public: 15.13 void set_direct_call( // sets entry to exact concrete method entry 15.14 Bytecodes::Code invoke_code, // the bytecode used for invoking the method 15.15 - methodHandle method // the method to call 15.16 + methodHandle method, // the method to call 15.17 + bool sender_is_interface 15.18 ); 15.19 15.20 void set_vtable_call( // sets entry to vtable index
16.1 --- a/src/share/vm/opto/doCall.cpp Mon Mar 27 08:21:39 2017 -0700 16.2 +++ b/src/share/vm/opto/doCall.cpp Mon Mar 27 11:31:27 2017 -0700 16.3 @@ -1,5 +1,5 @@ 16.4 /* 16.5 - * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. 16.6 + * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved. 16.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 16.8 * 16.9 * This code is free software; you can redistribute it and/or modify it 16.10 @@ -483,6 +483,30 @@ 16.11 speculative_receiver_type = receiver_type != NULL ? receiver_type->speculative_type() : NULL; 16.12 } 16.13 16.14 + // invoke-super-special 16.15 + if (iter().cur_bc_raw() == Bytecodes::_invokespecial && !orig_callee->is_object_initializer()) { 16.16 + ciInstanceKlass* calling_klass = method()->holder(); 16.17 + ciInstanceKlass* sender_klass = 16.18 + calling_klass->is_anonymous() ? calling_klass->host_klass() : 16.19 + calling_klass; 16.20 + if (sender_klass->is_interface()) { 16.21 + Node* receiver_node = stack(sp() - nargs); 16.22 + Node* cls_node = makecon(TypeKlassPtr::make(sender_klass)); 16.23 + Node* bad_type_ctrl = NULL; 16.24 + Node* casted_receiver = gen_checkcast(receiver_node, cls_node, &bad_type_ctrl); 16.25 + if (bad_type_ctrl != NULL) { 16.26 + PreserveJVMState pjvms(this); 16.27 + set_control(bad_type_ctrl); 16.28 + uncommon_trap(Deoptimization::Reason_class_check, 16.29 + Deoptimization::Action_none); 16.30 + } 16.31 + if (stopped()) { 16.32 + return; // MUST uncommon-trap? 16.33 + } 16.34 + set_stack(sp() - nargs, casted_receiver); 16.35 + } 16.36 + } 16.37 + 16.38 // Note: It's OK to try to inline a virtual call. 16.39 // The call generator will not attempt to inline a polymorphic call 16.40 // unless it knows how to optimize the receiver dispatch.
17.1 --- a/src/share/vm/prims/methodHandles.cpp Mon Mar 27 08:21:39 2017 -0700 17.2 +++ b/src/share/vm/prims/methodHandles.cpp Mon Mar 27 11:31:27 2017 -0700 17.3 @@ -1,5 +1,5 @@ 17.4 /* 17.5 - * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved. 17.6 + * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved. 17.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 17.8 * 17.9 * This code is free software; you can redistribute it and/or modify it 17.10 @@ -673,7 +673,7 @@ 17.11 defc, name, type, caller, THREAD); 17.12 } else if (ref_kind == JVM_REF_invokeSpecial) { 17.13 LinkResolver::resolve_special_call(result, 17.14 - defc, name, type, caller, caller.not_null(), THREAD); 17.15 + Handle(), defc, name, type, caller, caller.not_null(), THREAD); 17.16 } else if (ref_kind == JVM_REF_invokeVirtual) { 17.17 LinkResolver::resolve_virtual_call(result, Handle(), defc, 17.18 defc, name, type, caller, caller.not_null(), false, THREAD); 17.19 @@ -700,7 +700,7 @@ 17.20 assert(!HAS_PENDING_EXCEPTION, ""); 17.21 if (name == vmSymbols::object_initializer_name()) { 17.22 LinkResolver::resolve_special_call(result, 17.23 - defc, name, type, caller, caller.not_null(), THREAD); 17.24 + Handle(), defc, name, type, caller, caller.not_null(), THREAD); 17.25 } else { 17.26 break; // will throw after end of switch 17.27 }
18.1 --- a/src/share/vm/runtime/javaCalls.cpp Mon Mar 27 08:21:39 2017 -0700 18.2 +++ b/src/share/vm/runtime/javaCalls.cpp Mon Mar 27 11:31:27 2017 -0700 18.3 @@ -1,5 +1,5 @@ 18.4 /* 18.5 - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 18.6 + * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. 18.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 18.8 * 18.9 * This code is free software; you can redistribute it and/or modify it 18.10 @@ -231,7 +231,7 @@ 18.11 18.12 void JavaCalls::call_special(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) { 18.13 CallInfo callinfo; 18.14 - LinkResolver::resolve_special_call(callinfo, klass, name, signature, KlassHandle(), false, CHECK); 18.15 + LinkResolver::resolve_special_call(callinfo, args->receiver(), klass, name, signature, KlassHandle(), false, CHECK); 18.16 methodHandle method = callinfo.selected_method(); 18.17 assert(method.not_null(), "should have thrown exception"); 18.18