Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/NativeMethodsTestThread.java
41161 views
/*1* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22package nsk.share.jpda;2324import java.net.*;25import nsk.share.*;2627/*28* This thread class executes in loop native methods with different return types29*/30public class NativeMethodsTestThread extends Thread {3132static {33System.loadLibrary("NativeMethodsTestThread");34}3536native void VoidMethod(String message);3738native boolean BooleanMethod(String message);3940native byte ByteMethod(String message);4142native short ShortMethod(String message);4344native char CharMethod(String message);4546native int IntMethod(String message);4748native long LongMethod(String message);4950native float FloatMethod(String message);5152native double DoubleMethod(String message);5354native Object[] ObjectArrayMethod(String message);5556native String StringMethod(String message);5758native Thread ThreadMethod(String message);5960native ThreadGroup ThreadGroupMethod(String message);6162native Class ClassObjectMethod(String message);6364native ClassLoader ClassLoaderMethod(String message);6566native Object ObjectMethod(String message);6768native Boolean BooleanWrapperMethod(String message);6970native Byte ByteWrapperMethod(String message);7172native Short ShortWrapperMethod(String message);7374native Character CharWrapperMethod(String message);7576native Integer IntWrapperMethod(String message);7778native Long LongWrapperMethod(String message);7980native Float FloatWrapperMethod(String message);8182native Double DoubleWrapperMethod(String message);8384private void log(String message) {85log.display(message);86}8788public static boolean expectedBooleanValue = Boolean.TRUE;8990public static byte expectedByteValue = Byte.MAX_VALUE;9192public static char expectedCharValue = Character.MAX_VALUE;9394public static short expectedShortValue = Short.MAX_VALUE;9596public static int expectedIntValue = Integer.MAX_VALUE;9798public static long expectedLongValue = Long.MAX_VALUE;99100public static float expectedFloatValue = Float.MAX_VALUE;101102public static double expectedDoubleValue = Double.MAX_VALUE;103104public static Object[] expectedObjectArrayValue = new Object[1000];105106public static Thread expectedThreadValue = new Thread();107108public static ThreadGroup expectedThreadGroupValue = new ThreadGroup("Expected thread group");109110public static Class expectedClassObjectValue = NativeMethodsTestThread.class;111112public static ClassLoader expectedClassLoaderValue = new URLClassLoader(new URL[] {});113114public static String expectedStringValue = "EXPECTED STRING";115116public static Object expectedObjectValue = new Object();117118public static Boolean expectedBooleanWrapperValue = Boolean.valueOf(Boolean.TRUE);119120public static Byte expectedByteWrapperValue = Byte.valueOf(Byte.MAX_VALUE);121122public static Character expectedCharWrapperValue = Character.valueOf(Character.MAX_VALUE);123124public static Short expectedShortWrapperValue = Short.valueOf(Short.MAX_VALUE);125126public static Integer expectedIntWrapperValue = Integer.valueOf(Integer.MAX_VALUE);127128public static Long expectedLongWrapperValue = Long.valueOf(Long.MAX_VALUE);129130public static Float expectedFloatWrapperValue = Float.valueOf(Float.MAX_VALUE);131132public static Double expectedDoubleWrapperValue = Double.valueOf(Double.MAX_VALUE);133134// names of tested types, this names can be used to derive names of tested methods(typeName + 'Method'),135public static String testedTypesNames[] = {"Void", "Boolean", "Byte", "Short", "Char", "Int", "Long", "Float", "Double", "ObjectArray",136"String", "Thread", "ThreadGroup", "ClassObject", "ClassLoader", "Object", "BooleanWrapper", "ByteWrapper", "ShortWrapper",137"CharWrapper", "IntWrapper", "LongWrapper", "FloatWrapper", "DoubleWrapper" };138139private Log log;140141// is forceEarlyReturn would called for this thread142private boolean isTestThread;143144// how many times call all test methods145private int iterationsNumber = 1;146147// test thread wait on 'startExecutionWicket' in beginning of run()148private Wicket startExecutionWicket = new Wicket();149150private boolean success = true;151152public NativeMethodsTestThread(Log log, boolean isTestThread, int iterationNumber) {153this.log = log;154this.isTestThread = isTestThread;155156this.iterationsNumber = iterationNumber;157}158159private volatile boolean stopExecution;160161public void stopExecution() {162stopExecution = true;163}164165public void startExecuion() {166startExecutionWicket.unlockAll();167}168169public void run() {170// first, debuggee VM starts and suspends test threads to let debugger initialize breakpoints171startExecutionWicket.waitFor();172173int iterationCount = 0;174175// test thread executes test methods 'iterationNumber' times176// non-test thread execute until not interrupted177while ((iterationCount++ < iterationsNumber) || (!isTestThread && !stopExecution)) {178// execute test methods in order given in 'testMethodsNames' array179for (int i = 0; i < testedTypesNames.length; i++) {180executeMethod(testedTypesNames[i] + "Method");181}182}183184log("Test thread exit");185}186187// execute test method and check that correct value is returned188private void executeMethod(String methodName) {189String message = Thread.currentThread() + " in " + methodName;190if (methodName.equals("VoidMethod")) {191VoidMethod(message);192}193if (methodName.equals("BooleanMethod")) {194boolean result = BooleanMethod(message);195196log("Result: " + result);197}198if (methodName.equals("ByteMethod")) {199byte result = ByteMethod(message);200201log("Result: " + result);202}203if (methodName.equals("CharMethod")) {204char result = CharMethod(message);205206log("Result: " + result);207}208if (methodName.equals("ShortMethod")) {209short result = ShortMethod(message);210211log("Result: " + result);212}213if (methodName.equals("IntMethod")) {214int result = IntMethod(message);215216log("Result: " + result);217}218if (methodName.equals("LongMethod")) {219long result = LongMethod(message);220221log("Result: " + result);222}223if (methodName.equals("FloatMethod")) {224float result = FloatMethod(message);225226log("Result: " + result);227}228if (methodName.equals("DoubleMethod")) {229double result = DoubleMethod(message);230231log("Result: " + result);232}233if (methodName.equals("StringMethod")) {234String result = StringMethod(message);235236log("Result: " + result);237}238if (methodName.equals("ObjectMethod")) {239Object result = ObjectMethod(message);240241log("Result: " + result);242}243if (methodName.equals("ObjectArrayMethod")) {244Object[] result = ObjectArrayMethod(message);245246log("Result: " + result);247}248if (methodName.equals("ThreadMethod")) {249Thread result = ThreadMethod(message);250251log("Result: " + result);252}253if (methodName.equals("ThreadGroupMethod")) {254ThreadGroup result = ThreadGroupMethod(message);255256log("Result: " + result);257}258if (methodName.equals("ClassObjectMethod")) {259Class result = ClassObjectMethod(message);260261log("Result: " + result);262}263if (methodName.equals("ClassLoaderMethod")) {264ClassLoader result = ClassLoaderMethod(message);265266log("Result: " + result);267}268if (methodName.equals("BooleanWrapperMethod")) {269Boolean result = BooleanWrapperMethod(message);270271log("Result: " + result);272}273if (methodName.equals("ByteWrapperMethod")) {274Byte result = ByteWrapperMethod(message);275276log("Result: " + result);277}278if (methodName.equals("ShortWrapperMethod")) {279Short result = ShortWrapperMethod(message);280281log("Result: " + result);282}283if (methodName.equals("CharWrapperMethod")) {284Character result = CharWrapperMethod(message);285286log("Result: " + result);287}288if (methodName.equals("IntWrapperMethod")) {289Integer result = IntWrapperMethod(message);290291log("Result: " + result);292}293if (methodName.equals("LongWrapperMethod")) {294Long result = LongWrapperMethod(message);295296log("Result: " + result);297}298if (methodName.equals("FloatWrapperMethod")) {299Float result = FloatWrapperMethod(message);300301log("Result: " + result);302}303if (methodName.equals("DoubleWrapperMethod")) {304Double result = DoubleWrapperMethod(message);305306log("Result: " + result);307}308}309310public boolean getSuccess() {311return success;312}313}314315316