Path: blob/master/test/functional/cmdline_options_testresources/src/VMBench/GPTests/GPTest.java
6004 views
/*******************************************************************************1* Copyright (c) 2001, 2020 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/2122package VMBench.GPTests;2324import VMBench.GPTests.GPTest;2526public class GPTest implements Runnable {27static { System.loadLibrary("gptest"); }28String arg;2930public static int globalInt;31/**32*33* @param arg java.lang.String34*/35public GPTest(String arg) {36this.arg = arg;37}3839public native void gpFloat();40public native void gpIll();41public native void gpRead();42public native void gpWrite();43public native void gpSoftwareFloat();44public native void gpHardwareFloat();45public native void gpSoftwareRead();46public native void gpHardwareRead();47public native void gpAbort();4849public native void callBackIn();50public native void callInAndTriggerGPReadThenResumeAndCallInAgain();51public native void callInAndTriggerGPReadThenResumeAndReturnToJava(int count);5253/**54* Starts the application.55* @param args an array of command-line arguments56*/57public static void main(java.lang.String[] args) {58boolean thread = false;5960if (args.length != 1) {61if (args.length == 2 && args[0].equalsIgnoreCase("thread")) {62thread = true;63} else {64System.err.println("Incorrect args.");65System.err.println("Args: [thread] [float|ill|read|write|callin]");66System.err.println("If 'thread' is set the GP test runs in a child thread,");67System.err.println("otherwise it runs in the main thread.");68System.exit(1);69}70}7172GPTest test = new GPTest(args[args.length - 1]);73if (thread) {74new Thread(test).start();75} else {76test.run();77}78}79public void run() {8081if (arg.equalsIgnoreCase("softwareFloat")) {82this.gpSoftwareFloat();83System.err.println("Survived software-triggered SIGFPE!");84System.exit(3);85}8687if (arg.equalsIgnoreCase("hardwareFloat")) {88this.gpHardwareFloat();89System.err.println("Survived hardware-triggered SIGFPE!");90System.exit(3);91}9293if (arg.equalsIgnoreCase("softwareRead")) {94this.gpSoftwareRead();95System.err.println("Survived software-triggered SIGSEGV!");96System.exit(3);97}9899if (arg.equalsIgnoreCase("hardwareRead")) {100this.gpHardwareRead();101System.err.println("Survived hardware-triggered SIGSEGV!");102System.exit(3);103}104105if (arg.equalsIgnoreCase("abort")) {106System.out.println("Invoking abort!");107this.gpAbort();108System.err.println("Survived abort!");109System.exit(3);110}111112if (arg.equalsIgnoreCase("float")) {113114/* Call this multiple times for-XCEEHDLR to exercise running Java code following115* the conversion from LE Condition to Java ConditionException116*117* Calling it multiple times will not affect the non -XCEEHDLR case, as a crash is expected the first time 'round */118for (int i = 0; i < 50 ; i++) {119try {120this.gpFloat();121} catch (com.ibm.le.conditionhandling.ConditionException ce) {122byte []feedbackToken;123java.util.Locale locale = null;124125System.err.println("");126System.err.println("");127System.err.println(ce.toString());128System.err.println("\t" + ce.getRoutine() + ": " + ce.getOffsetInRoutine());129System.err.println("\tfacilityID: " + ce.getFacilityID());130System.err.println("\tseverity: " + ce.getSeverity());131System.err.println("\tmessageNumber: " + ce.getMessageNumber());132feedbackToken = ce.getToken();133System.err.print("\t feedback token: ");134for (int j = 0 ; j< feedbackToken.length ; j++) {135System.err.printf(locale, "%#x ", feedbackToken[j]);136}137System.err.println("\nSuccesfully threw exception " + (i + 1) + " times");138ce.printStackTrace();139}140}141System.err.println("Survived float gp!");142System.exit(2);143}144145if (arg.equalsIgnoreCase("ill")) {146this.gpIll();147System.err.println("Survived illegal instruction gp!");148System.exit(3);149}150151if (arg.equalsIgnoreCase("read")) {152this.gpRead();153System.err.println("Survived read gp!");154System.exit(4);155}156157if (arg.equalsIgnoreCase("write")) {158this.gpWrite();159System.err.println("Survived write gp!");160System.exit(5);161}162163if (arg.equalsIgnoreCase("callin")) {164this.callBackIn();165}166167if (arg.equalsIgnoreCase("callIn")) {168this.callBackIn();169}170171if (arg.equalsIgnoreCase("callInAndTriggerGPReadThenResumeAndCallInAgain")) {172this.callInAndTriggerGPReadThenResumeAndCallInAgain();173}174175if (arg.equalsIgnoreCase("callInAndTriggerGPReadThenResumeAndReturnToJava")) {176this.callInAndTriggerGPReadThenResumeAndReturnToJava(10);177}178179if (arg.equalsIgnoreCase("callInAndTriggerGPReadThenResumeAndReturnToJIT")) {180this.callInAndTriggerGPReadThenResumeAndReturnToJava_wrapper_wrapper();181}182183System.err.println("Unrecognized argument: " + arg);184System.exit(1);185186}187188public void callOut() {189this.gpRead();190System.err.println("Survived read gp!");191System.exit(4);192}193194public void callInAndTriggerGPReadThenResumeAndReturnToJava_wrapper_wrapper() {195196for (int i = 0 ; i < 100 ; i++) {197this.callInAndTriggerGPReadThenResumeAndReturnToJava_wrapper(i);198}199}200201public void callInAndTriggerGPReadThenResumeAndReturnToJava_wrapper(int count) {202203for (int i =0; i <100 ; i ++) {204globalInt = count;205}206207this.callInAndTriggerGPReadThenResumeAndReturnToJava(globalInt);208209}210211public void callOutAndTriggerGPRead() {212this.gpRead();213System.err.println("Survived read gp!");214System.exit(4);215}216217218}219220221