2023-04-27 09:00:58 +00:00
|
|
|
/*
|
2024-01-18 13:15:55 +00:00
|
|
|
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
|
2023-04-27 09:00:58 +00:00
|
|
|
* 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
|
|
|
|
* @library ../ /test/lib
|
2023-05-02 13:56:32 +00:00
|
|
|
* @requires jdk.foreign.linker != "FALLBACK"
|
2023-10-12 19:50:08 +00:00
|
|
|
* @run testng/othervm --enable-native-access=ALL-UNNAMED TestCriticalUpcall
|
2023-04-27 09:00:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import org.testng.annotations.Test;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.lang.foreign.FunctionDescriptor;
|
|
|
|
import java.lang.foreign.Linker;
|
|
|
|
import java.lang.foreign.MemorySegment;
|
|
|
|
import java.lang.invoke.MethodHandle;
|
2024-01-18 13:15:55 +00:00
|
|
|
import java.util.List;
|
2023-04-27 09:00:58 +00:00
|
|
|
|
|
|
|
import static org.testng.Assert.fail;
|
|
|
|
|
2023-10-12 19:50:08 +00:00
|
|
|
public class TestCriticalUpcall extends UpcallTestHelper {
|
2023-04-27 09:00:58 +00:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testUpcallFailure() throws IOException, InterruptedException {
|
|
|
|
// test to see if we catch a trivial downcall doing an upcall
|
2024-01-18 13:15:55 +00:00
|
|
|
runInNewProcess(Runner.class, true, List.of("-XX:-CreateCoredumpOnCrash"), List.of())
|
2023-12-13 17:34:37 +00:00
|
|
|
.shouldNotHaveExitValue(0)
|
|
|
|
.stdoutShouldContain("wrong thread state for upcall");
|
2023-04-27 09:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static class Runner extends NativeTestHelper {
|
|
|
|
public static void main(String[] args) throws Throwable {
|
2023-10-12 19:50:08 +00:00
|
|
|
System.loadLibrary("Critical");
|
2023-04-27 09:00:58 +00:00
|
|
|
|
2023-11-14 11:19:30 +00:00
|
|
|
MethodHandle mh = downcallHandle("do_upcall", FunctionDescriptor.ofVoid(C_POINTER), Linker.Option.critical(false));
|
2023-04-27 09:00:58 +00:00
|
|
|
MemorySegment stub = upcallStub(Runner.class, "target", FunctionDescriptor.ofVoid());
|
|
|
|
mh.invokeExact(stub);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void target() {
|
|
|
|
fail("Should not get here");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|