diff --git a/src/cpu/sparc/vm/stubGenerator_sparc.cpp b/src/cpu/sparc/vm/stubGenerator_sparc.cpp index a7fe854e069f477d9512edf5ee2775553505e4ff..cf403040dfabf6d960f63e92217074ba5e5e0db3 100644 --- a/src/cpu/sparc/vm/stubGenerator_sparc.cpp +++ b/src/cpu/sparc/vm/stubGenerator_sparc.cpp @@ -436,7 +436,7 @@ class StubGenerator: public StubCodeGenerator { #undef __ #define __ masm-> - address generate_throw_exception(const char* name, address runtime_entry, bool restore_saved_exception_pc, + address generate_throw_exception(const char* name, address runtime_entry, Register arg1 = noreg, Register arg2 = noreg) { #ifdef ASSERT int insts_size = VerifyThread ? 1 * K : 600; @@ -462,11 +462,6 @@ class StubGenerator: public StubCodeGenerator { int frame_complete = __ offset(); - if (restore_saved_exception_pc) { - __ ld_ptr(G2_thread, JavaThread::saved_exception_pc_offset(), I7); - __ sub(I7, frame::pc_return_offset, I7); - } - // Note that we always have a runtime stub frame on the top of stack by this point Register last_java_sp = SP; // 64-bit last_java_sp is biased! @@ -3418,7 +3413,7 @@ class StubGenerator: public StubCodeGenerator { StubRoutines::_throw_WrongMethodTypeException_entry = generate_throw_exception("WrongMethodTypeException throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_WrongMethodTypeException), - false, G5_method_type, G3_method_handle); + G5_method_type, G3_method_handle); } @@ -3429,12 +3424,10 @@ class StubGenerator: public StubCodeGenerator { // UseZeroBaseCompressedOops which is defined after heap initialization. StubRoutines::Sparc::_partial_subtype_check = generate_partial_subtype_check(); // These entry points require SharedInfo::stack0 to be set up in non-core builds - StubRoutines::_throw_AbstractMethodError_entry = generate_throw_exception("AbstractMethodError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_AbstractMethodError), false); - StubRoutines::_throw_IncompatibleClassChangeError_entry= generate_throw_exception("IncompatibleClassChangeError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_IncompatibleClassChangeError), false); - StubRoutines::_throw_ArithmeticException_entry = generate_throw_exception("ArithmeticException throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_ArithmeticException), true); - StubRoutines::_throw_NullPointerException_entry = generate_throw_exception("NullPointerException throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_NullPointerException), true); - StubRoutines::_throw_NullPointerException_at_call_entry= generate_throw_exception("NullPointerException at call throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_NullPointerException_at_call), false); - StubRoutines::_throw_StackOverflowError_entry = generate_throw_exception("StackOverflowError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_StackOverflowError), false); + StubRoutines::_throw_AbstractMethodError_entry = generate_throw_exception("AbstractMethodError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_AbstractMethodError)); + StubRoutines::_throw_IncompatibleClassChangeError_entry= generate_throw_exception("IncompatibleClassChangeError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_IncompatibleClassChangeError)); + StubRoutines::_throw_NullPointerException_at_call_entry= generate_throw_exception("NullPointerException at call throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_NullPointerException_at_call)); + StubRoutines::_throw_StackOverflowError_entry = generate_throw_exception("StackOverflowError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_StackOverflowError)); StubRoutines::_handler_for_unsafe_access_entry = generate_handler_for_unsafe_access(); diff --git a/src/cpu/x86/vm/methodHandles_x86.cpp b/src/cpu/x86/vm/methodHandles_x86.cpp index 0e5d1599e5e6551bae805ffa7094122148b02000..dd741fda0d85d4b9e024dce42b59df7038bbf34a 100644 --- a/src/cpu/x86/vm/methodHandles_x86.cpp +++ b/src/cpu/x86/vm/methodHandles_x86.cpp @@ -624,6 +624,11 @@ address MethodHandles::generate_method_handle_interpreter_entry(MacroAssembler* // error path for invokeExact (only) __ bind(invoke_exact_error_path); + // ensure that the top of stack is properly aligned. + __ mov(rdi, rsp); + __ andptr(rsp, -StackAlignmentInBytes); // Align the stack for the ABI + __ pushptr(Address(rdi, 0)); // Pick up the return address + // Stub wants expected type in rax and the actual type in rcx __ jump(ExternalAddress(StubRoutines::throw_WrongMethodTypeException_entry())); diff --git a/src/cpu/x86/vm/stubGenerator_x86_32.cpp b/src/cpu/x86/vm/stubGenerator_x86_32.cpp index c0a6ec358ea75bd51e1f2257088d7c8c7449d32f..e8a85336149b93d340aef35d0cc24e55621b6c66 100644 --- a/src/cpu/x86/vm/stubGenerator_x86_32.cpp +++ b/src/cpu/x86/vm/stubGenerator_x86_32.cpp @@ -2187,7 +2187,7 @@ class StubGenerator: public StubCodeGenerator { // either at call sites or otherwise assume that stack unwinding will be initiated, // so caller saved registers were assumed volatile in the compiler. address generate_throw_exception(const char* name, address runtime_entry, - bool restore_saved_exception_pc, Register arg1 = noreg, Register arg2 = noreg) { + Register arg1 = noreg, Register arg2 = noreg) { int insts_size = 256; int locs_size = 32; @@ -2204,10 +2204,6 @@ class StubGenerator: public StubCodeGenerator { // differently than the real call_VM Register java_thread = rbx; __ get_thread(java_thread); - if (restore_saved_exception_pc) { - __ movptr(rax, Address(java_thread, in_bytes(JavaThread::saved_exception_pc_offset()))); - __ push(rax); - } __ enter(); // required for proper stackwalking of RuntimeStub frame @@ -2323,7 +2319,7 @@ class StubGenerator: public StubCodeGenerator { StubRoutines::_throw_WrongMethodTypeException_entry = generate_throw_exception("WrongMethodTypeException throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_WrongMethodTypeException), - false, rax, rcx); + rax, rcx); } @@ -2332,12 +2328,10 @@ class StubGenerator: public StubCodeGenerator { // These entry points require SharedInfo::stack0 to be set up in non-core builds // and need to be relocatable, so they each fabricate a RuntimeStub internally. - StubRoutines::_throw_AbstractMethodError_entry = generate_throw_exception("AbstractMethodError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_AbstractMethodError), false); - StubRoutines::_throw_IncompatibleClassChangeError_entry= generate_throw_exception("IncompatibleClassChangeError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_IncompatibleClassChangeError), false); - StubRoutines::_throw_ArithmeticException_entry = generate_throw_exception("ArithmeticException throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_ArithmeticException), true); - StubRoutines::_throw_NullPointerException_entry = generate_throw_exception("NullPointerException throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_NullPointerException), true); - StubRoutines::_throw_NullPointerException_at_call_entry= generate_throw_exception("NullPointerException at call throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_NullPointerException_at_call), false); - StubRoutines::_throw_StackOverflowError_entry = generate_throw_exception("StackOverflowError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_StackOverflowError), false); + StubRoutines::_throw_AbstractMethodError_entry = generate_throw_exception("AbstractMethodError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_AbstractMethodError)); + StubRoutines::_throw_IncompatibleClassChangeError_entry= generate_throw_exception("IncompatibleClassChangeError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_IncompatibleClassChangeError)); + StubRoutines::_throw_NullPointerException_at_call_entry= generate_throw_exception("NullPointerException at call throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_NullPointerException_at_call)); + StubRoutines::_throw_StackOverflowError_entry = generate_throw_exception("StackOverflowError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_StackOverflowError)); //------------------------------------------------------------------------------------------------------------------------ // entry points that are platform specific diff --git a/src/cpu/x86/vm/stubGenerator_x86_64.cpp b/src/cpu/x86/vm/stubGenerator_x86_64.cpp index 095412b033254565fa082cd9705bbae2630c8dae..a58b8d9eb9e14e8e8c2bc1c3a536a7423587d9c2 100644 --- a/src/cpu/x86/vm/stubGenerator_x86_64.cpp +++ b/src/cpu/x86/vm/stubGenerator_x86_64.cpp @@ -935,6 +935,8 @@ class StubGenerator: public StubCodeGenerator { __ pusha(); // push registers Address next_pc(rsp, RegisterImpl::number_of_registers * BytesPerWord); + // FIXME: this probably needs alignment logic + __ subptr(rsp, frame::arg_reg_save_area_bytes); BLOCK_COMMENT("call handle_unsafe_access"); __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, handle_unsafe_access))); @@ -2934,7 +2936,6 @@ class StubGenerator: public StubCodeGenerator { // caller saved registers were assumed volatile in the compiler. address generate_throw_exception(const char* name, address runtime_entry, - bool restore_saved_exception_pc, Register arg1 = noreg, Register arg2 = noreg) { // Information about frame layout at time of blocking runtime call. @@ -2962,12 +2963,6 @@ class StubGenerator: public StubCodeGenerator { // which has the ability to fetch the return PC out of // thread-local storage and also sets up last_Java_sp slightly // differently than the real call_VM - if (restore_saved_exception_pc) { - __ movptr(rax, - Address(r15_thread, - in_bytes(JavaThread::saved_exception_pc_offset()))); - __ push(rax); - } __ enter(); // required for proper stackwalking of RuntimeStub frame @@ -3068,7 +3063,7 @@ class StubGenerator: public StubCodeGenerator { StubRoutines::_throw_WrongMethodTypeException_entry = generate_throw_exception("WrongMethodTypeException throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_WrongMethodTypeException), - false, rax, rcx); + rax, rcx); } void generate_all() { @@ -3081,43 +3076,25 @@ class StubGenerator: public StubCodeGenerator { generate_throw_exception("AbstractMethodError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime:: - throw_AbstractMethodError), - false); + throw_AbstractMethodError)); StubRoutines::_throw_IncompatibleClassChangeError_entry = generate_throw_exception("IncompatibleClassChangeError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime:: - throw_IncompatibleClassChangeError), - false); - - StubRoutines::_throw_ArithmeticException_entry = - generate_throw_exception("ArithmeticException throw_exception", - CAST_FROM_FN_PTR(address, - SharedRuntime:: - throw_ArithmeticException), - true); - - StubRoutines::_throw_NullPointerException_entry = - generate_throw_exception("NullPointerException throw_exception", - CAST_FROM_FN_PTR(address, - SharedRuntime:: - throw_NullPointerException), - true); + throw_IncompatibleClassChangeError)); StubRoutines::_throw_NullPointerException_at_call_entry = generate_throw_exception("NullPointerException at call throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime:: - throw_NullPointerException_at_call), - false); + throw_NullPointerException_at_call)); StubRoutines::_throw_StackOverflowError_entry = generate_throw_exception("StackOverflowError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime:: - throw_StackOverflowError), - false); + throw_StackOverflowError)); // entry points that are platform specific StubRoutines::x86::_f2i_fixup = generate_f2i_fixup(); diff --git a/src/cpu/zero/vm/stubGenerator_zero.cpp b/src/cpu/zero/vm/stubGenerator_zero.cpp index 77d23a4ffb70e8a3bda3e40929ba80495268399c..b13c0f3ef8f245d0ca9fb7554b9ae2b0b0d3ca28 100644 --- a/src/cpu/zero/vm/stubGenerator_zero.cpp +++ b/src/cpu/zero/vm/stubGenerator_zero.cpp @@ -215,12 +215,6 @@ class StubGenerator: public StubCodeGenerator { StubRoutines::_throw_AbstractMethodError_entry = ShouldNotCallThisStub(); - StubRoutines::_throw_ArithmeticException_entry = - ShouldNotCallThisStub(); - - StubRoutines::_throw_NullPointerException_entry = - ShouldNotCallThisStub(); - StubRoutines::_throw_NullPointerException_at_call_entry = ShouldNotCallThisStub(); diff --git a/src/share/vm/runtime/stubRoutines.cpp b/src/share/vm/runtime/stubRoutines.cpp index 5f77761a249f0aed12127b01988374f32716241a..f38173f0f1dc8e6a8b984cee89c7c72d72b1c830 100644 --- a/src/share/vm/runtime/stubRoutines.cpp +++ b/src/share/vm/runtime/stubRoutines.cpp @@ -51,8 +51,6 @@ address StubRoutines::_catch_exception_entry = NULL; address StubRoutines::_forward_exception_entry = NULL; address StubRoutines::_throw_AbstractMethodError_entry = NULL; address StubRoutines::_throw_IncompatibleClassChangeError_entry = NULL; -address StubRoutines::_throw_ArithmeticException_entry = NULL; -address StubRoutines::_throw_NullPointerException_entry = NULL; address StubRoutines::_throw_NullPointerException_at_call_entry = NULL; address StubRoutines::_throw_StackOverflowError_entry = NULL; address StubRoutines::_throw_WrongMethodTypeException_entry = NULL; diff --git a/src/share/vm/runtime/stubRoutines.hpp b/src/share/vm/runtime/stubRoutines.hpp index e2ca75c812a682dbb3e9203a694d439f39022369..8481dce6dcac6ffe45de5a85f3570266f05d2092 100644 --- a/src/share/vm/runtime/stubRoutines.hpp +++ b/src/share/vm/runtime/stubRoutines.hpp @@ -128,8 +128,6 @@ class StubRoutines: AllStatic { static address _catch_exception_entry; static address _throw_AbstractMethodError_entry; static address _throw_IncompatibleClassChangeError_entry; - static address _throw_ArithmeticException_entry; - static address _throw_NullPointerException_entry; static address _throw_NullPointerException_at_call_entry; static address _throw_StackOverflowError_entry; static address _throw_WrongMethodTypeException_entry; @@ -254,8 +252,6 @@ class StubRoutines: AllStatic { // Implicit exceptions static address throw_AbstractMethodError_entry() { return _throw_AbstractMethodError_entry; } static address throw_IncompatibleClassChangeError_entry(){ return _throw_IncompatibleClassChangeError_entry; } - static address throw_ArithmeticException_entry() { return _throw_ArithmeticException_entry; } - static address throw_NullPointerException_entry() { return _throw_NullPointerException_entry; } static address throw_NullPointerException_at_call_entry(){ return _throw_NullPointerException_at_call_entry; } static address throw_StackOverflowError_entry() { return _throw_StackOverflowError_entry; } static address throw_WrongMethodTypeException_entry() { return _throw_WrongMethodTypeException_entry; } diff --git a/test/compiler/7088020/Test7088020.java b/test/compiler/7088020/Test7088020.java new file mode 100644 index 0000000000000000000000000000000000000000..4ea991340bde54eacb45a35a557f62aa7c3ed717 --- /dev/null +++ b/test/compiler/7088020/Test7088020.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/** + * @test + * @bug 7088020 + * @summary SEGV in JNIHandleBlock::release_block + * + * @run main Test7088020 + */ + +import java.lang.invoke.*; + + +public class Test7088020 { + public static boolean test() { + return false; + } + + public static void main(String... args) throws Throwable { + MethodHandle test = MethodHandles.lookup().findStatic(Test7088020.class, "test", MethodType.methodType(Boolean.TYPE)); + + // Exercise WMT with different argument alignments + int thrown = 0; + try { + test.invokeExact(0); + } catch (WrongMethodTypeException wmt) { + thrown++; + if (wmt.getStackTrace().length < 1) throw new InternalError("missing stack frames"); + } + try { + test.invokeExact(0, 1); + } catch (WrongMethodTypeException wmt) { + thrown++; + if (wmt.getStackTrace().length < 1) throw new InternalError("missing stack frames"); + } + try { + test.invokeExact(0, 1, 2); + } catch (WrongMethodTypeException wmt) { + thrown++; + if (wmt.getStackTrace().length < 1) throw new InternalError("missing stack frames"); + } + try { + test.invokeExact(0, 1, 2, 3); + } catch (WrongMethodTypeException wmt) { + thrown++; + if (wmt.getStackTrace().length < 1) throw new InternalError("missing stack frames"); + } + try { + thrown++; + test.invokeExact(0, 1, 2, 3, 4); + } catch (WrongMethodTypeException wmt) { + if (wmt.getStackTrace().length < 1) throw new InternalError("missing stack frames"); + } + if (thrown != 5) { + throw new InternalError("not enough throws"); + } + } +}