changeset 50459:44839fbb20db

8199643: [TESTBUG] Open source common VM testbase code Reviewed-by: vlivanov, erikj, mseledtsov, gthornbr
author iignatyev
date Mon, 30 Apr 2018 18:10:24 -0700
parents c63bdf53a1a7
children 2ace90aec488
files make/test/JtregNativeHotspot.gmk test/hotspot/jtreg/vmTestbase/ExecDriver.java test/hotspot/jtreg/vmTestbase/PropertyResolvingWrapper.java test/hotspot/jtreg/vmTestbase/README.md test/hotspot/jtreg/vmTestbase/nsk/share/AbstractGoldChecker.java test/hotspot/jtreg/vmTestbase/nsk/share/ArgumentParser.java test/hotspot/jtreg/vmTestbase/nsk/share/ClassFileFinder.java test/hotspot/jtreg/vmTestbase/nsk/share/ClassUnloader.java test/hotspot/jtreg/vmTestbase/nsk/share/Consts.java test/hotspot/jtreg/vmTestbase/nsk/share/CustomClassLoader.java test/hotspot/jtreg/vmTestbase/nsk/share/Debug.java test/hotspot/jtreg/vmTestbase/nsk/share/Denotation.java test/hotspot/jtreg/vmTestbase/nsk/share/DummyClassLoader.java test/hotspot/jtreg/vmTestbase/nsk/share/Failure.java test/hotspot/jtreg/vmTestbase/nsk/share/FileUtils.java test/hotspot/jtreg/vmTestbase/nsk/share/Finalizable.java test/hotspot/jtreg/vmTestbase/nsk/share/FinalizableObject.java test/hotspot/jtreg/vmTestbase/nsk/share/Finalizer.java test/hotspot/jtreg/vmTestbase/nsk/share/GoldChecker.java test/hotspot/jtreg/vmTestbase/nsk/share/Grep.java test/hotspot/jtreg/vmTestbase/nsk/share/Harakiri.java test/hotspot/jtreg/vmTestbase/nsk/share/IORedirector.java test/hotspot/jtreg/vmTestbase/nsk/share/JVMDITools.c test/hotspot/jtreg/vmTestbase/nsk/share/JVMDITools.h test/hotspot/jtreg/vmTestbase/nsk/share/JVMTIagent.c test/hotspot/jtreg/vmTestbase/nsk/share/LocalProcess.java test/hotspot/jtreg/vmTestbase/nsk/share/Log.java test/hotspot/jtreg/vmTestbase/nsk/share/NativeUtils.java test/hotspot/jtreg/vmTestbase/nsk/share/ObjectInstancesManager.java test/hotspot/jtreg/vmTestbase/nsk/share/Oddity.java test/hotspot/jtreg/vmTestbase/nsk/share/Pair.java test/hotspot/jtreg/vmTestbase/nsk/share/Paragrep.java test/hotspot/jtreg/vmTestbase/nsk/share/PrintProperties.java test/hotspot/jtreg/vmTestbase/nsk/share/RASagent.java test/hotspot/jtreg/vmTestbase/nsk/share/README test/hotspot/jtreg/vmTestbase/nsk/share/ReferringObject.java test/hotspot/jtreg/vmTestbase/nsk/share/ReferringObjectSet.java test/hotspot/jtreg/vmTestbase/nsk/share/StringGoldChecker.java test/hotspot/jtreg/vmTestbase/nsk/share/TestBug.java test/hotspot/jtreg/vmTestbase/nsk/share/TestFailure.java test/hotspot/jtreg/vmTestbase/nsk/share/TestJNIError.java test/hotspot/jtreg/vmTestbase/nsk/share/TimeoutHandler.java test/hotspot/jtreg/vmTestbase/nsk/share/TreeNodesDenotation.java test/hotspot/jtreg/vmTestbase/nsk/share/Wicket.java test/hotspot/jtreg/vmTestbase/nsk/share/aod/AODRunnerArgParser.java test/hotspot/jtreg/vmTestbase/nsk/share/aod/AODTargetArgParser.java test/hotspot/jtreg/vmTestbase/nsk/share/aod/AODTestRunner.java test/hotspot/jtreg/vmTestbase/nsk/share/aod/AbstractJarAgent.java test/hotspot/jtreg/vmTestbase/nsk/share/aod/AgentInformation.java test/hotspot/jtreg/vmTestbase/nsk/share/aod/AgentsAttacher.java test/hotspot/jtreg/vmTestbase/nsk/share/aod/DummyTargetApplication.java test/hotspot/jtreg/vmTestbase/nsk/share/aod/ProcessExecutor.java test/hotspot/jtreg/vmTestbase/nsk/share/aod/TargetApplicationWaitingAgents.java test/hotspot/jtreg/vmTestbase/nsk/share/aod/Utils.java test/hotspot/jtreg/vmTestbase/nsk/share/aod/aod.c test/hotspot/jtreg/vmTestbase/nsk/share/aod/aod.h test/hotspot/jtreg/vmTestbase/nsk/share/classload/ClassPathNonDelegatingClassLoader.java test/hotspot/jtreg/vmTestbase/nsk/share/classload/GeneratingClassLoader.java test/hotspot/jtreg/vmTestbase/nsk/share/classload/TemplateClass.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/Algorithms.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/AllDiag.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/AllMemoryObject.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/ArgumentHandler.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/Cell.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/CircularLinkedList.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/ClassChain.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/FinDiag.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/FinMemoryObject.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/FinMemoryObject1.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/GC.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/GCParams.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/GCParamsAware.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/GCTestBase.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/IndexPair.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/LinkedMemoryObject.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/Matrix.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/Memory.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/MemoryObject.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/NonbranchyTree.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/OOMStress.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/ThreadedGCTest.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/TwoFieldsObject.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/classes/Classes.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/DerivedProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/DerivedStrategyProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/GarbageProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/GarbageProducer1Aware.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/GarbageProducerAware.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/GarbageProducers.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/GarbageUtils.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/MemoryStrategy.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/MemoryStrategyAware.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/RandomProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/array/ArrayOfProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/array/ArrayProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/array/BooleanArrayProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/array/ByteArrayProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/array/CharArrayProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/array/DoubleArrayProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/array/FloatArrayProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/array/IntArrayProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/array/LongArrayProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/array/ObjectArrayProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/array/ShortArrayProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/classload/GeneratedClassProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/list/CircularListProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/list/LinearListProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/misc/HashedGarbageProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/misc/TraceProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/misc/TwoFieldsObjectProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/obj/AllMemoryObjectProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/obj/FinMemoryObject1Producer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/obj/FinMemoryObjectProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/obj/MemoryObjectProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/string/InternedStringProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/string/RandomStringProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/string/SimpleStringProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/gp/tree/NonbranchyTreeProducer.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/CriticalSectionLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/CriticalSectionObjectLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/CriticalSectionTimedLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/Locker.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/LockerUtils.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/Lockers.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/LockersAware.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/MultiLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/BooleanArrayCriticalLocker.c test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/BooleanArrayCriticalLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ByteArrayCriticalLocker.c test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ByteArrayCriticalLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/CharArrayCriticalLocker.c test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/CharArrayCriticalLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/DoubleArrayCriticalLocker.c test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/DoubleArrayCriticalLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/FloatArrayCriticalLocker.c test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/FloatArrayCriticalLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/IntArrayCriticalLocker.c test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/IntArrayCriticalLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/JNILockers.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/LongArrayCriticalLocker.c test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/LongArrayCriticalLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ShortArrayCriticalLocker.c test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ShortArrayCriticalLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/StringCriticalLocker.c test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/StringCriticalLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIGlobalRefLocker.c test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIGlobalRefLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIGlobalRefLockers.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNILocalRefLocker.c test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNILocalRefLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNILocalRefLockers.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIRefLocker.c test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIRefLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIRefLockers.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIWeakGlobalRefLocker.c test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIWeakGlobalRefLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIWeakGlobalRefLockers.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jvmti/JVMTIAllocLocker.c test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jvmti/JVMTIAllocLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jvmti/JVMTIAllocLockers.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/malloc/MallocLocker.c test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/malloc/MallocLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/malloc/MallocLockers.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/tree/Tree.java test/hotspot/jtreg/vmTestbase/nsk/share/gc/tree/TreeNode.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/AbstractJDIDebuggee.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/ArgumentHandler.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/Binder.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/ConnectorTest.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/Debugee.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/DebuggeeEventData.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/DebuggerEventData.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/EventFilters.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/EventHandler.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/EventTestTemplates.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/ForceEarlyReturnDebugger.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/HeapwalkingDebuggee.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/HeapwalkingDebugger.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/JDIEventsDebuggee.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/JDIEventsDebugger.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/MockReferenceType.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/MonitorEnterExecutor.c test/hotspot/jtreg/vmTestbase/nsk/share/jdi/MonitorEventsDebuggee.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/OwnedMonitorsDebuggee.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/OwnedMonitorsDebugger.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/PlugConnectors.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/PlugTransportService.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/SerialExecutionDebuggee.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/SerialExecutionDebugger.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/TestClass1.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/TestClass2.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/TestDebuggerType1.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/TestDebuggerType2.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/TestInterfaceImplementer1.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/ThreadState.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/ValueConversionDebugger.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/sde/InstallSDE.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/sde/SDEDebuggee.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/sde/SDEDebugger.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/sde/SmapGenerator.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/sde/SmapStratum.java test/hotspot/jtreg/vmTestbase/nsk/share/jdi/sde/TestClass1.java test/hotspot/jtreg/vmTestbase/nsk/share/jni/JNIreferences.c test/hotspot/jtreg/vmTestbase/nsk/share/jni/README test/hotspot/jtreg/vmTestbase/nsk/share/jni/jni_tools.c test/hotspot/jtreg/vmTestbase/nsk/share/jni/jni_tools.h test/hotspot/jtreg/vmTestbase/nsk/share/jpda/AbstractDebuggeeTest.java test/hotspot/jtreg/vmTestbase/nsk/share/jpda/BindServer.java test/hotspot/jtreg/vmTestbase/nsk/share/jpda/ConversionUtils.java test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeArgumentHandler.java test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeBinder.java test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeProcess.java test/hotspot/jtreg/vmTestbase/nsk/share/jpda/ForceEarlyReturnTestThread.java test/hotspot/jtreg/vmTestbase/nsk/share/jpda/IOPipe.java test/hotspot/jtreg/vmTestbase/nsk/share/jpda/SocketConnection.java test/hotspot/jtreg/vmTestbase/nsk/share/jpda/SocketIOPipe.java test/hotspot/jtreg/vmTestbase/nsk/share/jpda/StateTestThread.java test/hotspot/jtreg/vmTestbase/nsk/share/locks/DeadlockLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/locks/DeadlockMaker.java test/hotspot/jtreg/vmTestbase/nsk/share/locks/DeadlockedThread.java test/hotspot/jtreg/vmTestbase/nsk/share/locks/JNIMonitorLocker.c test/hotspot/jtreg/vmTestbase/nsk/share/locks/JNIMonitorLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/locks/LockType.java test/hotspot/jtreg/vmTestbase/nsk/share/locks/LockingThread.c test/hotspot/jtreg/vmTestbase/nsk/share/locks/LockingThread.java test/hotspot/jtreg/vmTestbase/nsk/share/locks/MonitorLockingThread.java test/hotspot/jtreg/vmTestbase/nsk/share/locks/ReentrantLockLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/locks/SynchronizedBlockLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/locks/SynchronizedMethodLocker.java test/hotspot/jtreg/vmTestbase/nsk/share/log/Log.java test/hotspot/jtreg/vmTestbase/nsk/share/log/LogAware.java test/hotspot/jtreg/vmTestbase/nsk/share/log/LogSupport.java test/hotspot/jtreg/vmTestbase/nsk/share/native/README test/hotspot/jtreg/vmTestbase/nsk/share/native/native_thread.c test/hotspot/jtreg/vmTestbase/nsk/share/native/native_thread.h test/hotspot/jtreg/vmTestbase/nsk/share/native/native_utils.c test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_list.c test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_list.h test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_mutex.c test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_mutex.h test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_tools.c test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_tools.h test/hotspot/jtreg/vmTestbase/nsk/share/runner/FinRunner.java test/hotspot/jtreg/vmTestbase/nsk/share/runner/GCRunner.java test/hotspot/jtreg/vmTestbase/nsk/share/runner/MemDiag.java test/hotspot/jtreg/vmTestbase/nsk/share/runner/MultiRunner.java test/hotspot/jtreg/vmTestbase/nsk/share/runner/MultiRunnerAware.java test/hotspot/jtreg/vmTestbase/nsk/share/runner/RunParams.java test/hotspot/jtreg/vmTestbase/nsk/share/runner/RunParamsAware.java test/hotspot/jtreg/vmTestbase/nsk/share/runner/ThreadsRunner.java test/hotspot/jtreg/vmTestbase/nsk/share/sysdict/ClassLoadersBTree.java test/hotspot/jtreg/vmTestbase/nsk/share/sysdict/ClassLoadersChain.java test/hotspot/jtreg/vmTestbase/nsk/share/test/Dumpable.java test/hotspot/jtreg/vmTestbase/nsk/share/test/ExecutionController.java test/hotspot/jtreg/vmTestbase/nsk/share/test/Initializable.java test/hotspot/jtreg/vmTestbase/nsk/share/test/LazyFormatString.java test/hotspot/jtreg/vmTestbase/nsk/share/test/LazyIntArrayToString.java test/hotspot/jtreg/vmTestbase/nsk/share/test/LazyObjectArrayToString.java test/hotspot/jtreg/vmTestbase/nsk/share/test/LocalRandom.java test/hotspot/jtreg/vmTestbase/nsk/share/test/StressOptions.java test/hotspot/jtreg/vmTestbase/nsk/share/test/Stresser.java test/hotspot/jtreg/vmTestbase/nsk/share/test/Test.java test/hotspot/jtreg/vmTestbase/nsk/share/test/TestBase.java test/hotspot/jtreg/vmTestbase/nsk/share/test/TestExitCode.java test/hotspot/jtreg/vmTestbase/nsk/share/test/TestUtils.java test/hotspot/jtreg/vmTestbase/nsk/share/test/Tests.java test/hotspot/jtreg/vmTestbase/nsk/share/test/timeoutwatchdog/TimeoutHandler.java test/hotspot/jtreg/vmTestbase/nsk/share/test/timeoutwatchdog/TimeoutWatchdog.java test/hotspot/jtreg/vmTestbase/vm/share/CommentedFileReader.java test/hotspot/jtreg/vmTestbase/vm/share/FileUtils.java test/hotspot/jtreg/vmTestbase/vm/share/InMemoryJavaCompiler.java test/hotspot/jtreg/vmTestbase/vm/share/ProcessUtils.c test/hotspot/jtreg/vmTestbase/vm/share/ProcessUtils.java test/hotspot/jtreg/vmTestbase/vm/share/RandomEx.java test/hotspot/jtreg/vmTestbase/vm/share/StringUtils.java test/hotspot/jtreg/vmTestbase/vm/share/UnsafeAccess.java test/hotspot/jtreg/vmTestbase/vm/share/VMRuntimeEnvUtils.java test/hotspot/jtreg/vmTestbase/vm/share/gc/TriggerUnloadingByFillingHeap.java test/hotspot/jtreg/vmTestbase/vm/share/gc/TriggerUnloadingByFillingMetaspace.java test/hotspot/jtreg/vmTestbase/vm/share/gc/TriggerUnloadingHelper.java test/hotspot/jtreg/vmTestbase/vm/share/gc/TriggerUnloadingWithWhiteBox.java test/hotspot/jtreg/vmTestbase/vm/share/libProcessUtils.c test/hotspot/jtreg/vmTestbase/vm/share/monitoring/MemoryPoolFinder.java test/hotspot/jtreg/vmTestbase/vm/share/monitoring/data/MemoryManagerData.java test/hotspot/jtreg/vmTestbase/vm/share/monitoring/data/MemoryPoolData.java test/hotspot/jtreg/vmTestbase/vm/share/monitoring/data/MemoryUsageData.java test/hotspot/jtreg/vmTestbase/vm/share/options/BasicObjectFactory.java test/hotspot/jtreg/vmTestbase/vm/share/options/BasicOptionObjectFactory.java test/hotspot/jtreg/vmTestbase/vm/share/options/FClass.java test/hotspot/jtreg/vmTestbase/vm/share/options/Factory.java test/hotspot/jtreg/vmTestbase/vm/share/options/IgnoreUnknownArgumentsHandler.java test/hotspot/jtreg/vmTestbase/vm/share/options/ObjectFactory.java test/hotspot/jtreg/vmTestbase/vm/share/options/Option.java test/hotspot/jtreg/vmTestbase/vm/share/options/OptionDefinition.java test/hotspot/jtreg/vmTestbase/vm/share/options/OptionError.java test/hotspot/jtreg/vmTestbase/vm/share/options/OptionHandler.java test/hotspot/jtreg/vmTestbase/vm/share/options/OptionObjectFactory.java test/hotspot/jtreg/vmTestbase/vm/share/options/OptionSupport.java test/hotspot/jtreg/vmTestbase/vm/share/options/Options.java test/hotspot/jtreg/vmTestbase/vm/share/options/OptionsMap.java test/hotspot/jtreg/vmTestbase/vm/share/options/OptionsSetup.java test/hotspot/jtreg/vmTestbase/vm/share/options/ParserException.java test/hotspot/jtreg/vmTestbase/vm/share/options/PrimitiveParser.java test/hotspot/jtreg/vmTestbase/vm/share/options/package-info.java test/hotspot/jtreg/vmTestbase/vm/share/options/test/BasicObjectFactoryUsageExample.java test/hotspot/jtreg/vmTestbase/vm/share/options/test/ExampleWithNonprimitiveOptions.java test/hotspot/jtreg/vmTestbase/vm/share/options/test/SimpleExample.java test/hotspot/jtreg/vmTestbase/vm/share/options/test/SimpleExampleWithOptionsAnnotation.java test/hotspot/jtreg/vmTestbase/vm/share/options/test/SubClassExample.java test/hotspot/jtreg/vmTestbase/vm/share/options/test/package-info.java test/hotspot/jtreg/vmTestbase/vm/share/process/CmdExecutor.java test/hotspot/jtreg/vmTestbase/vm/share/process/MessageInput.java test/hotspot/jtreg/vmTestbase/vm/share/process/MessageOutput.java test/hotspot/jtreg/vmTestbase/vm/share/process/ProcessExecutor.java test/hotspot/jtreg/vmTestbase/vm/share/process/ProcessHandler.java test/hotspot/jtreg/vmTestbase/vm/share/process/StreamListener.java test/hotspot/jtreg/vmTestbase/vm/share/process/StreamLogger.java test/hotspot/jtreg/vmTestbase/vm/share/process/StreamMessageInput.java test/hotspot/jtreg/vmTestbase/vm/share/process/StreamMessageOutput.java test/hotspot/jtreg/vmTestbase/vm/share/process/StreamReader.java test/hotspot/jtreg/vmTestbase/vm/share/stack/StackUtils.java test/hotspot/jtreg/vmTestbase/vm/share/transform/AbstractClassFileTransformer.java test/hotspot/jtreg/vmTestbase/vm/share/transform/AnnotationAppender.java test/hotspot/jtreg/vmTestbase/vm/share/transform/TransformingClassLoader.java test/hotspot/jtreg/vmTestbase/vm/share/vmcrasher/Crasher.java test/hotspot/jtreg/vmTestbase/vm/share/vmcrasher/CrasherFactory.java test/hotspot/jtreg/vmTestbase/vm/share/vmcrasher/SignalCrasher.java test/hotspot/jtreg/vmTestbase/vm/share/vmcrasher/UnsafeGCCrasher.java test/hotspot/jtreg/vmTestbase/vm/share/vmcrasher/UnsafeJavaCrasher.java test/hotspot/jtreg/vmTestbase/vm/share/vmstresser/CompileAndDeoptimize.java test/hotspot/jtreg/vmTestbase/vm/share/vmstresser/MetaspaceStresser.java
diffstat 331 files changed, 58155 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/make/test/JtregNativeHotspot.gmk	Mon Apr 30 20:29:19 2018 -0400
+++ b/make/test/JtregNativeHotspot.gmk	Mon Apr 30 18:10:24 2018 -0700
@@ -48,6 +48,21 @@
 
 BUILD_HOTSPOT_JTREG_IMAGE_DIR := $(TEST_IMAGE_DIR)/hotspot/jtreg
 
+################################################################################
+# Former VM TestBase tests.
+################################################################################
+
+VM_TESTBASE_DIR := $(TOPDIR)/test/hotspot/jtreg/vmTestbase
+
+VM_SHARE_INCLUDES := \
+    -I$(VM_TESTBASE_DIR)/vm/share \
+    -I$(VM_TESTBASE_DIR)/nsk/share/native \
+    -I$(VM_TESTBASE_DIR)/nsk/share/jni
+
+BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libProcessUtils := $(VM_SHARE_INCLUDES)
+
+################################################################################
+
 # Platform specific setup
 ifneq ($(OPENJDK_TARGET_OS)-$(OPENJDK_TARGET_CPU_ARCH), solaris-sparc)
   BUILD_HOTSPOT_JTREG_EXCLUDE += liboverflow.c exeThreadSignalMask.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/ExecDriver.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,170 @@
+/*
+ * Copyright (c) 2017, 2018, 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.
+ */
+
+import jdk.test.lib.Platform;
+import jdk.test.lib.Utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+
+/**
+ * Starts a new process to execute a command.
+ * <p>Usage: --java|--cmd|--launcher <arg>+
+ * <p>If {@code --cmd} flag is specified, the arguments are treated as
+ * a program to run and its arguments. Non-zero exit code of the created process
+ * will be reported as an {@link AssertionError}.
+ * <p>If {@code --java} flag is specified, the arguments are passed to {@code java}
+ * from JDK under test. If exit code doesn't equal to 0 or 95, {@link AssertionError}
+ * will be thrown.
+ * <p>If {@code --launcher} flag is specified, the arguments treated similar as
+ * for {@code --cmd}, but the started process will have the directory which
+ * contains {@code jvm.so} in dynamic library path, and {@code test.class.path}
+ * as CLASSPATH environment variable. Exit codes are checked as in
+ * {@code --java}, i.e. 0 or 95 means pass.
+ */
+public class ExecDriver {
+    public static void main(String[] args) throws IOException, InterruptedException {
+        boolean java = false;
+        boolean launcher = false;
+
+        String type = args[0];
+        switch (type) {
+            case "--java":
+                String[] oldArgs = args;
+                int count;
+                String libraryPath = System.getProperty("test.nativepath");
+                if (libraryPath != null && !libraryPath.isEmpty()) {
+                    count = 4;
+                    args = new String[args.length + 3];
+                    args[3] = "-Djava.library.path=" + libraryPath;
+                } else {
+                    count = 3;
+                    args = new String[args.length + 2];
+                }
+                args[0] = javaBin();
+                args[1] = "-cp";
+                args[2] = Utils.TEST_CLASS_PATH;
+                System.arraycopy(oldArgs, 1, args, count, oldArgs.length - 1);
+                java = true;
+                break;
+            case "--launcher":
+                java = true;
+                launcher = true;
+            case "--cmd":
+                args = Arrays.copyOfRange(args, 1, args.length);
+                break;
+            default:
+                throw new Error("unknown type: " + type);
+        }
+        // adding 'test.vm.opts' and 'test.java.opts'
+        if (java) {
+            String[] oldArgs = args;
+            String[] testJavaOpts = Utils.getTestJavaOpts();
+            if (testJavaOpts.length > 0) {
+                args = new String[args.length + testJavaOpts.length];
+                // bin/java goes before options
+                args[0] = oldArgs[0];
+                // then external java options
+                System.arraycopy(testJavaOpts, 0, args, 1, testJavaOpts.length);
+                // and then options and args from a test
+                System.arraycopy(oldArgs, 1, args, 1 + testJavaOpts.length, oldArgs.length - 1);
+            }
+        }
+        String command = Arrays.toString(args);
+        System.out.println("exec " + command);
+
+        ProcessBuilder pb = new ProcessBuilder(args);
+        // adding jvm.so to library path
+        if (launcher) {
+            Path dir = Paths.get(Utils.TEST_JDK);
+            String name;
+            if (Platform.isWindows()) {
+                dir = dir.resolve("bin")
+                         .resolve(variant())
+                         .toAbsolutePath();
+                name = "PATH";
+            } else {
+                dir = dir.resolve("lib")
+                         .resolve(variant())
+                         .toAbsolutePath();
+                name = Platform.isOSX() ? "DYLD_LIBRARY_PATH" : "LD_LIBRARY_PATH";
+            }
+
+            System.out.println("  with " + name + " = " +
+                    pb.environment()
+                      .merge(name, dir.toString(), (x, y) -> y + File.pathSeparator + x));
+            System.out.println("  with CLASSPATH = " +
+                    pb.environment()
+                      .put("CLASSPATH", Utils.TEST_CLASS_PATH));
+        }
+        Process p = pb.start();
+        // inheritIO does not work as expected for @run driver
+        new Thread(() -> copy(p.getInputStream(), System.out)).start();
+        new Thread(() -> copy(p.getErrorStream(), System.out)).start();
+        int exitCode = p.waitFor();
+
+        if (exitCode != 0 && (!java || exitCode != 95)) {
+            throw new AssertionError(command + " exit code is " + exitCode);
+        }
+    }
+
+    private static String variant() {
+        if (Platform.isServer()) {
+            return "server";
+        } else if (Platform.isClient()) {
+            return "client";
+        } else if (Platform.isMinimal()) {
+            return "minimal";
+        } else {
+            throw new Error("TESTBUG: unsuppported vm variant");
+        }
+    }
+
+
+    private static void copy(InputStream is, OutputStream os) {
+        byte[] buffer = new byte[1024];
+        int n;
+        try (InputStream close = is) {
+            while ((n = is.read(buffer)) != -1) {
+                os.write(buffer, 0, n);
+            }
+            os.flush();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    private static String javaBin() {
+        return Paths.get(Utils.TEST_JDK)
+                    .resolve("bin")
+                    .resolve("java")
+                    .toAbsolutePath()
+                    .toString();
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/PropertyResolvingWrapper.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2017, 2018, 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.
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * Replaces all {@code ${<X>}} with value of corresponding property({@code X}),
+ * resulting string is handled similarly to {@code @run main} in jtreg.
+ * In other words, {@code main} of first token will be executed with the rest
+ * tokens as arguments.
+ *
+ * If one of properties can't be resolved, {@link Error} will be thrown.
+ */
+public class PropertyResolvingWrapper {
+    private static final Properties properties;
+    static {
+        Properties p = System.getProperties();
+        String name = p.getProperty("os.name");
+        String arch = p.getProperty("os.arch");
+        String family;
+        String simple_arch;
+
+        // copy from jtreg/src/share/classes/com/sun/javatest/regtest/config/OS.java
+        if (name.startsWith("AIX"))
+            family = "aix";
+        else if (name.startsWith("Linux"))
+            family = "linux";
+        else if (name.startsWith("Mac") || name.startsWith("Darwin"))
+            family = "mac";
+        else if (name.startsWith("OS400") || name.startsWith("OS/400") )
+            family = "os400";
+        else if (name.startsWith("SunOS") || name.startsWith("Solaris"))
+            family = "solaris";
+        else if (name.startsWith("Windows"))
+            family = "windows";
+        else
+            family = name.replaceFirst("^([^ ]+).*", "$1"); // use first word of name
+
+        if (arch.contains("64")
+                 && !arch.equals("ia64")
+                 && !arch.equals("ppc64")
+                 && !arch.equals("ppc64le")
+                 && !arch.equals("zArch_64")
+                 && !arch.equals("aarch64"))
+             simple_arch = "x64";
+        else if (arch.contains("86"))
+            simple_arch = "i586";
+        else if (arch.equals("ppc") || arch.equals("powerpc"))
+            simple_arch = "ppc";
+        else if (arch.equals("s390x") || arch.equals("zArch_64"))
+            simple_arch = "s390x";
+        else
+            simple_arch = arch;
+
+        p.setProperty("os.family", family);
+        p.setProperty("os.simpleArch", simple_arch);
+        properties = p;
+    }
+
+    public static void main(String[] args) throws Throwable {
+        List<String> command = new ArrayList<>(args.length);
+        for (int i = 0; i < args.length; ++i) {
+            StringBuilder arg = new StringBuilder(args[i]);
+            while (i < args.length - 1
+                    && (arg.chars()
+                       .filter(c -> c == '"')
+                       .count() % 2) != 0) {
+                arg.append(" ")
+                   .append(args[++i]);
+            }
+            command.add(eval(arg.toString()));
+        }
+        System.out.println("run " + command);
+        try {
+            Class.forName(command.remove(0))
+                 .getMethod("main", String[].class)
+                 .invoke(null, new Object[]{command.toArray(new String[0])});
+        } catch (InvocationTargetException e) {
+           Throwable t = e.getCause();
+           t = t != null ? t : e;
+           throw t;
+        }
+    }
+
+    private static String eval(String string) {
+        int index;
+        int current = 0;
+        StringBuilder result = new StringBuilder();
+        while (current < string.length() && (index = string.indexOf("${", current)) >= 0) {
+            result.append(string.substring(current, index));
+            int endName = string.indexOf('}', index);
+            current = endName + 1;
+            String name = string.substring(index + 2, endName);
+            String value = properties.getProperty(name);
+            if (value == null) {
+                throw new Error("can't find property " + name);
+            }
+            result.append(value);
+        }
+        if (current < string.length()) {
+            result.append(string.substring(current));
+        }
+        int length = result.length();
+
+        if (length > 1 && result.charAt(0) == '"' && result.charAt(length - 1) == '"') {
+            result.deleteCharAt(length - 1);
+            result.deleteCharAt(0);
+        }
+        return result.toString();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/README.md	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,10 @@
+# VM Testbase landing
+
+This directory serves as a _temporary_ landing place for tests converted from so-called VM testbase.
+Most of these tests have been written a long time ago, don't meet modern coding
+standards, guidelines and are in need of reworking.
+Eventually, all the tests located here should be reworked and moved accordingly to
+regular JTReg test suite directory layout convention, i.e. following the same
+layout as product code as close as possible.
+
+New tests must **not** be added into this directory.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/AbstractGoldChecker.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,164 @@
+/*
+ * Copyright (c) 2008, 2018, 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.
+ */
+package nsk.share;
+import java.io.UnsupportedEncodingException;
+
+public abstract class AbstractGoldChecker {
+
+    private final StringBuffer sb = new StringBuffer();
+
+    protected abstract String getGoldenString();
+
+    public void print(boolean b) {
+        sb.append(String.valueOf(b));
+    }
+
+    public void print(byte b) {
+        sb.append(String.valueOf(b));
+    }
+
+    public void print(char c) {
+        sb.append(String.valueOf(c));
+    }
+
+    public void print(int i) {
+        sb.append(String.valueOf(i));
+    }
+
+    public void print(long l) {
+        sb.append(String.valueOf(l));
+    }
+
+    public void print(float f) {
+        sb.append(String.valueOf(f));
+    }
+
+    public void print(double d) {
+        sb.append(String.valueOf(d));
+    }
+
+    public void print(String s) {
+        sb.append(s);
+    }
+
+    public void println() {
+        sb.append('\n');
+    }
+
+    public void println(boolean b) {
+        sb.append(String.valueOf(b));
+        sb.append('\n');
+    }
+
+    public void println(byte b) {
+        sb.append(String.valueOf(b));
+        sb.append('\n');
+    }
+
+    public void println(char c) {
+        sb.append(String.valueOf(c));
+        sb.append('\n');
+    }
+
+    public void println(int i) {
+        sb.append(String.valueOf(i));
+        sb.append('\n');
+    }
+
+    public void println(long l) {
+        sb.append(String.valueOf(l));
+        sb.append('\n');
+    }
+
+    public void println(float f) {
+        sb.append(String.valueOf(f));
+        sb.append('\n');
+    }
+
+    public void println(double d) {
+        sb.append(String.valueOf(d));
+        sb.append('\n');
+    }
+
+    public void println(String s) {
+        sb.append(s);
+        sb.append('\n');
+    }
+
+    public void check() {
+        String testOutput;
+        try {
+            testOutput = new String(sb.toString().getBytes("US-ASCII"), "US-ASCII");
+        } catch (UnsupportedEncodingException e) {
+            throw new TestFailure(e);
+        }
+
+        String goldOutput = getGoldenString();
+        if (!compare(testOutput, goldOutput)) {
+            throw new TestFailure(
+                "Gold comparison failed\n" +
+                "\n" +
+                "Test output:\n" +
+                "============\n" +
+                "\n" +
+                testOutput +
+                "\n" +
+                "------------\n" +
+                "\n" +
+                "Gold output:\n" +
+                "============\n" +
+                "\n" +
+                goldOutput +
+                "\n" +
+                "------------\n" +
+                "\n"
+           );
+        }
+    }
+
+    public boolean compare(String src, String dst) {
+        int i1 = 0;
+        int i2 = 0;
+
+        int src_len = src.length();
+        int dst_len = dst.length();
+
+        while ((i1 < src_len) && (i2 < dst_len)) {
+
+            char c1 = src.charAt(i1++);
+            if ((c1 == '\r') && (i1 < src_len)) {
+                c1 = src.charAt(i1++);
+            }
+
+            char c2 = dst.charAt(i2++);
+            if ((c2 == '\r') && (i2 < dst_len)) {
+                c2 = dst.charAt(i2++);
+            }
+
+            if (c1 != c2) {
+                return false;
+            }
+        }
+        return (i1 == src_len) && (i2 == dst_len);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/ArgumentParser.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,507 @@
+/*
+ * Copyright (c) 2001, 2018, 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.
+ */
+
+package nsk.share;
+
+import java.util.*;
+
+import nsk.share.test.StressOptions;
+import nsk.share.test.Stresser;
+
+/**
+ * Parser for JDI test's command-line arguments.
+ * <p>
+ * Test's command line may contain two kind of arguments, namely:
+ * <ul>
+ * <li> options for ArgumentParser
+ * <li> other arguments for the test itself
+ * </ul>
+ * <p>
+ * We call <i>raw arguments</i> the <code>args[]</code> array
+ * passed to the test's method <code>main(String&nbsp;args[])</code>.
+ * ArgumentParser instance initialized with raw arguments serves to parse
+ * these two kinds of arguments. Use <code>ArgumentParser(args[])</code>
+ * constructor, or <code>setRawArguments(args[])</code> method
+ * to initialize a ArgumentParser instance with particular raw arguments.
+ * <p>
+ * Arguments, started with ``<code>-</code>'' symbol are called <i>options</i>.
+ * They are recognized by ArgumentParser and are used by support classes
+ * (such as Log, Binder, etc.).
+ * These options should be specified in the following general form:
+ * <ul>
+ * <li> <code>-option=<i>value</i></code>
+ * </ul>
+ * or
+ * <ul>
+ * <li> <code>-option <i>value</i></code>
+ * </ul>
+ * List of the recognized options with their values may be obtained by
+ * invoking method <code>getOptions()</code> that returnes
+ * a <code>Properties</code> object with options values.
+ * It is not recommended to get options value directly. An appropriate methods
+ * such as <code>verbose()</code>, <code>getArch()</code>, etc. should be used
+ * instead.
+ * Options may appear in the test command line in any order.
+ * <p>
+ * All the other arguments of command line are called <i>test arguments</i>
+ * (or simply <i>arguments</i>). These arguments should be handled by test itself.
+ * Full list of the test arguments in the same order as they appears in the command line
+ * may be obtained by invoking method <code>getArguments()</code>.
+ * <p>
+ * Following is the list of basic options accepted by AgrumentParser:
+ * <ul>
+ * <li> <code>-arch=</code>&lt;<i>${ARCH}</i>&gt; -
+ *   architecture name
+ * <li> <code>-waittime=</code>&lt;<i>minutes</i>&gt; -
+ *   timeout in minutes for waiting events or so
+ * <li> <code>-verbose</code> -
+ *   verbose Log mode (default is quiet)
+ * <li> <code>-trace.time</code> -
+ *   prefix log messages with timestamps (default is no)
+ * </ul>
+ * Also AgrumentParser supports following stress options (see nsk.share.test.StressOptions for details):
+ * <ul>
+ * <li> <code>-stressTime</code>
+ * <li> <code>-stressIterationsFactor</code>
+ * <li> <code>-stressThreadsFactor</code>
+ * <li> <code>-stressDebug</code>
+ * </ul>
+ * <p>
+ * Note, that the tests from the particular subsuites have its own argument handlers
+ * wich accepts additional options. See <code>jpda.DebugeeArgumentHandler</code>,
+ * <code>jdi.ArgumentHandler</code>, <code>jdwp.ArgumentHandler</code>.
+ *
+ * @see #setRawArguments(String[])
+ * @see #getRawArguments()
+ * @see #getArguments()
+ * @see #getOptions()
+ *
+ * @see nsk.share.jpda.DebugeeArgumentHandler
+ * @see nsk.share.jdwp.ArgumentHandler
+ * @see nsk.share.jdi.ArgumentHandler
+ * @see nsk.share.jvmti.ArgumentHandler
+ * @see nsk.share.monitoring.ArgumentHandler
+ */
+public class ArgumentParser {
+
+    /**
+     * Raw array of command-line arguments.
+     *
+     * @see #setRawArguments(String[])
+     * @see #getRawArguments()
+     */
+    protected String rawArguments[] = null;
+
+    /**
+     * Refined arguments -- raw arguments but options.
+     *
+     * @see #options
+     * @see #getArguments()
+     */
+    protected String arguments[] = null;
+
+    /**
+     * Recognized options for ArgumentParser class.
+     *
+     * @see #arguments
+     * @see #getOptions()
+     */
+    protected Properties options = new Properties();
+
+    /**
+     * Make new ArgumentParser object with default values of otions.
+     * This constructor is used only to obtain default values of options.
+     *
+     * @see #setRawArguments(String[])
+     */
+    protected ArgumentParser() {
+        String[] args = new String[0];
+        setRawArguments(args);
+    }
+
+    /**
+     * Keep a copy of raw command-line arguments and parse them;
+     * but throw an exception on parsing error.
+     *
+     * @param  args  Array of the raw command-line arguments.
+     *
+     * @throws  BadOption  If option values are invalid.
+     *
+     * @see #setRawArguments(String[])
+     * @see BadOption
+     */
+    public ArgumentParser(String args[]) {
+        setRawArguments(args);
+    }
+
+    /**
+     * Return a copy of the raw command-line arguments kept by
+     * this ArgumentParser instance.
+     *
+     * @throws  NullPointerException  If raw arguments were not
+     *                                set for this instance.
+     *
+     * @see #setRawArguments(String[])
+     */
+    public String[] getRawArguments() {
+        return (String[]) rawArguments.clone();
+    }
+
+    /**
+     * Return given raw command-line argument.
+     *
+     * @param index index of argument
+     * @return value of raw argument
+     */
+    public String getRawArgument(int index) {
+            return rawArguments[index];
+    }
+
+    /**
+     * Return refined array of test arguments (only those of the raw
+     * arguments which are not recognized as options for ArgumentParser).
+     *
+     * <p>Note, that sintax of test arguments was not checked;
+     * while syntax of arguments describing ArgumentParser's options
+     * was checked while raw arguments were set to this ArgumentParser
+     * instance.
+     *
+     * @throws  NullPointerException  If raw arguments were not
+     *                                set for this instance.
+     *
+     * @see #setRawArguments(String[])
+     * @see #getOptions()
+     */
+    public String[] getArguments() {
+        return (String[]) arguments.clone();
+    }
+
+    /**
+     * Return list of recognized otions with their values in the form of
+     * <code>Properties</code> object.
+     * If no options has been recognized, this list will be empty.
+     *
+     * @see #setRawArguments(String[])
+     * @see #getArguments()
+     */
+    public Properties getOptions() {
+        return (Properties) options.clone();
+    }
+
+    /**
+     * Join specified arguments into one line using given quoting
+     * and separator symbols.
+     *
+     * @param args Array of the command-line arguments
+     * @param quote Symbol used to quote each argument
+     * @param separator Symbol used as separator between argumnets
+     * @return Single line with arguments
+     */
+    static public String joinArguments(String args[], String quote, String separator) {
+        if (args.length <= 0) {
+            return "";
+        }
+        String line = quote + args[0] + quote;
+        for (int i = 1; i < args.length; i++) {
+            line += separator + quote + args[i] + quote;
+        }
+        return line;
+    }
+
+    /**
+     * Join specified arguments into one line using given quoting symbol
+     * and space as a separator symbol.
+     *
+     * @param args Array of the command-line arguments
+     * @param quote Symbol used to quote each argument
+     * @return Single line with arguments
+     */
+    static public String joinArguments(String args[], String quote) {
+        return joinArguments(args, quote, " ");
+    }
+
+    /**
+     * Keep a copy of command-line arguments and parse them;
+     * but throw an exception on parsing error.
+     *
+     * @param  args  Array of the raw command-line arguments.
+     *
+     * @throws  BadOption  If an option has invalid value.
+     *
+     * @see #getRawArguments()
+     * @see #getArguments()
+     */
+    public void setRawArguments(String args[]) {
+        this.rawArguments = (String[]) args.clone();
+        parseArguments();
+    }
+
+    /**
+     * Add or replace given option value in options list and in raw arguments list.
+     * Use specified <code>rawPrefix</code> while adding to raw arguments list.
+     *
+     * @see #getRawArguments()
+     * @see #getOptions()
+     */
+    public void setOption(String rawPrefix, String name, String value) {
+        String prefix = rawPrefix + name + "=";
+        String arg = prefix + value;
+
+        options.setProperty(name, value);
+
+        int length = rawArguments.length;
+        boolean found = false;
+        for (int i = 0; i < length; i++) {
+            if (rawArguments[i].startsWith(prefix)) {
+                found = true;
+                rawArguments[i] = arg;
+                break;
+            }
+        }
+
+        if (!found) {
+            String[] newRawArguments = new String[length + 1];
+            for (int i = 0; i < length; i++) {
+                newRawArguments[i] = rawArguments[i];
+            }
+            newRawArguments[length] = arg;
+            rawArguments = newRawArguments;
+        }
+    }
+
+    /**
+     * Return current architecture name from ArgumentParser's
+     * options.
+     *
+     * <p>Note that null string is returning if test argument
+     * <code>-arch</code> has not been set.
+     *
+     * @see #setRawArguments(String[])
+     */
+    public String getArch() {
+        return options.getProperty("arch");
+    }
+
+    /**
+     * Timeout (in minutes) for test's critical section like:
+     * (a) awaiting for an event, or conversly (b) making sure
+     * that there is no unexpected event.
+     *
+     * <p>By default, <i>2</i> minutes is returned if option
+     * <code>-waittime</code> is not set with command line.
+     *
+     * @see TimeoutHandler
+     */
+    public int getWaitTime() {
+        String val = options.getProperty("waittime", "2");
+        int minutes;
+        try {
+            minutes = Integer.parseInt(val);
+        } catch (NumberFormatException e) {
+            throw new TestBug("Not integer value of \"waittime\" argument: " + val);
+        }
+        return minutes;
+    }
+
+    /**
+     * Return boolean value of current Log mode:
+     * <ul>
+     * <li><i>true</i> if Log mode is verbose.
+     * <li><i>false</i> otherwise.
+     *
+     * <p>Note that default Log mode is quiet if test argument
+     * <code>-verbose</code> has not been set.
+     *
+     * @see #setRawArguments(String[])
+     */
+    public boolean verbose() {
+        return options.getProperty("verbose") != null;
+    }
+
+    /**
+     * Return boolean value of setting of timestamp for log messages:
+     * <ul>
+     * <li><i>true</i> if Log messages are timestamp'ed.
+     * <li><i>false</i> otherwise.
+     *
+     * <p>Note that by default Log messages won't be timestamp'ed until
+     * <code>-trace.time</code> has not been set.
+     *
+     * @see #setRawArguments(String[])
+     */
+    public boolean isTimestamp() {
+        return options.getProperty("trace.time") != null;
+    }
+
+    /**
+     * Return level of printing tracing mesages for debugging purpose.
+     * Level <i>0</i> means no tracing messages at all.
+     *
+     * <p>Note that by default no tracing messages will be printed out
+     * until <code>-trace.level</code> has not been set.
+     *
+     * @see #setRawArguments(String[])
+     */
+    public int getTraceLevel() {
+        String value = options.getProperty("trace.level", Integer.toString(Log.TraceLevel.DEFAULT));
+        try {
+            int level = Integer.parseInt(value);
+            return level;
+        } catch (NumberFormatException e) {
+            throw new Failure("Not integer value of -trace.level option: " + value);
+        }
+    }
+
+    /**
+     * Parse arguments from rawArgumnets, extact recognized options,
+     * check legality of options values options and store non-option
+     * arguments.
+     *
+     * @throws  NullPointerException  If raw arguments were not set
+     *                                for this ArgumentParser instance.
+     * @throws  BadOption If Option name is not accepted or
+     *                    option has illegal value.
+     *
+     * @see #setRawArguments(String[])
+     * @see #checkOption(String, String)
+     * @see #checkOptions()
+     */
+    protected void parseArguments() {
+        String selected[] = new String [rawArguments.length];
+        Properties properties = new Properties();
+        int count = 0;
+        for (int i=0; i<rawArguments.length; i++) {
+            String argument = rawArguments[i];
+            if (argument.startsWith("-")) {
+                int pos = argument.indexOf("=", 1);
+                String option, value;
+                if (pos < 0) {
+                    option = argument.substring(1);
+                    if (i + 1 < rawArguments.length && !rawArguments[i + 1].startsWith("-")) {
+                        value = rawArguments[i + 1];
+                        ++i;
+                    } else
+                        value = "";
+                } else {
+                    option = argument.substring(1, pos);
+                    value = argument.substring(pos + 1);
+                }
+                if (!checkOption(option, value)) {
+                    throw new BadOption("Unrecognized command line option: " + argument);
+                }
+                properties.setProperty(option, value);
+            } else {
+                selected[count++] = rawArguments[i];
+            }
+        }
+        // Strip away the dummy tail of the selected[] array:
+        arguments = new String [count];
+        System.arraycopy(selected,0,arguments,0,count);
+        options = properties;
+        checkOptions();
+    }
+
+    public StressOptions getStressOptions() {
+        return new StressOptions(rawArguments);
+    }
+
+    /**
+     * Check if the specified option is allowed and has legal value.
+     * <p>
+     * Derived classes for hadling test arguments in particular sub-suites
+     * override this method to allow to accept sub-suite specific options.
+     * However, they should invoke this method of the base class to enshure
+     * that the basic options will be accepted too.
+     *
+     * @return <i>true</i> if option is allowed and has legel value
+     *         <i>false</I> if option is unknown
+     *
+     * @throws  BadOption  If value of the allowed option is illegal.
+     *
+     * @see #setRawArguments(String[])
+     * @see #parseArguments()
+     */
+    protected boolean checkOption(String option, String value) {
+
+        // accept arguments of nsk.share.test.StressOptions
+        if (StressOptions.isValidStressOption(option))
+            return true;
+
+        // options with any string value
+        if (option.equals("arch")) {
+            return true;
+        }
+
+        // options with positive integer value
+        if (option.equals("waittime")
+            || option.equals("trace.level")) {
+            try {
+                int number = Integer.parseInt(value);
+                if (number < 0) {
+                    throw new BadOption(option + ": value must be a positive integer");
+                }
+            } catch (NumberFormatException e) {
+                throw new BadOption(option + ": value must be an integer");
+            }
+            return true;
+        }
+
+        // options without any value
+        if (option.equals("verbose")
+            || option.equals("vbs")
+            || option.equals("trace.time")) {
+            if (!(value == null || value.length() <= 0)) {
+                throw new BadOption(option + ": no value must be specified");
+            }
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * Check that the value of all options are not inconsistent.
+     * This method is invoked by <code>parseArguments()</code>
+     *
+     * @throws  BadOption  If value of the options are inconsistent
+     *
+     * @see #parseArguments()
+     */
+    protected void checkOptions() {
+        // do nothing
+    }
+
+    /**
+     * Thrown if invalid option or option value is found.
+     */
+    public static class BadOption extends IllegalArgumentException {
+        /**
+         * Explain the reason.
+         *
+         * @param  message   Printing message.
+         */
+        public BadOption(String message) {
+            super(message);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/ClassFileFinder.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+package nsk.share;
+
+import java.io.File;
+import java.nio.file.Paths;
+import java.nio.file.Path;
+import java.nio.file.Files;
+import java.util.Arrays;
+
+public class ClassFileFinder {
+    private ClassFileFinder() { }
+    /**
+     * Searches for a classfile for the specified class in the specified
+     * classpath.
+     *
+     * @param name a classname
+     * @param classPath @{link File.pathSeparator} separated directories
+     * @return an absolute path to the found classfile, or null if it cannot be
+     *         found
+     */
+    public static Path findClassFile(String name, String classPath) {
+        return Arrays.stream(classPath.split(File.pathSeparator))
+                     .map(java.nio.file.Paths::get)
+                     .map(p -> p.resolve(name.replace('.', File.separatorChar) + ".class"))
+                     .filter(p -> java.nio.file.Files.exists(p))
+                     .map(Path::toAbsolutePath)
+                     .findAny()
+                     .orElse(null);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/ClassUnloader.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,352 @@
+/*
+ * Copyright (c) 2001, 2018, 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.
+ */
+
+/*
+ *  Warning! Using this component need VM option -XX:-UseGCOverheadLimit
+ *
+ */
+
+package nsk.share;
+
+import java.util.*;
+import nsk.share.gc.gp.*;
+import nsk.share.test.ExecutionController;
+import nsk.share.test.Stresser;
+
+/**
+ * The <code>ClassUnloader</code> class allows to force VM to unload class(es)
+ * using memory stressing technique.
+ *
+ * <p>The method <code>unloadClass()</code> is provided which eats memory
+ * to enforce GC to cleanup the heap. So, if all references to a class
+ * and its loader are canceled, this may result in unloading the class.
+ *
+ * <p>ClassUnloader mainly intends to unload a class which was loaded
+ * with especial <code>ClassUnloader.loadClass()</code> method.
+ * A class is considered unloaded if its class loader is finalized.
+ * If there no finalization of class loader detected for some timeout,
+ * class is considered still loaded and method returns <i>false</i>.
+ *
+ * <p>Such finalization control applies only to a class loaded by
+ * ClassUnloader's <code>loadClass()</code> method. Otherwise, if there
+ * was no such class loaded, <code>unloadClass()</code> doesn't wait
+ * for a timeout and always returns <i>false</i>.
+ *
+ * <p>By default internal class loader of <code>CustomClassLoader</code> class
+ * is used for loading classes. This class loader can load class from .class file
+ * located in the specified directory.
+ * Application may define its own class loader, which may load classes using
+ * any other technique. Such class loader should be derived from base
+ * <code>CustomClassLoader</code> class, and set by <code>setClassLoader()</code>
+ * method.
+ *
+ * @see #setClassLoader(CustomClassLoader)
+ * @see #loadClass(String)
+ * @see #loadClass(String, String)
+ * @see #unloadClass()
+ */
+public class ClassUnloader {
+
+    /**
+     * Class name of default class loader.
+     */
+    public static final String INTERNAL_CLASS_LOADER_NAME = "nsk.share.CustomClassLoader";
+
+    /**
+     * Whole amount of time in milliseconds to wait for class loader finalization.
+     */
+    private static final int WAIT_TIMEOUT = 15000;
+
+    /**
+     * Piece of time in milliseconds to wait in a loop for class loader finalization.
+     */
+    private static final int WAIT_DELTA = 1000;
+
+    /**
+     * Has class loader been finalized or not.
+     */
+    volatile boolean finalized = false;
+
+    /**
+     * Current class loader used for loading classes.
+     */
+    private CustomClassLoader customClassLoader = null;
+
+    /**
+     * List of classes loaded with current class loader.
+     */
+    private Vector<Class<?>> classObjects = new Vector<Class<?>>();
+
+    /**
+     * Class object of the first class been loaded with current class loader.
+     * To get the rest loaded classes use <code>getLoadedClass(int)</code>.
+     * The call <code>getLoadedClass()</code> is effectively equivalent to the call
+     * <code>getLoadedClass(0)</code>
+     *
+     * @return class object of the first loaded class.
+     *
+     * @see #getLoadedClass(int)
+     */
+    public Class<?> getLoadedClass() {
+        return classObjects.get(0);
+    }
+
+    /**
+     * Returns class objects at the specified index in the list of classes loaded
+     * with current class loader.
+     *
+     * @return class objects at the specified index.
+     */
+    public Class<?> getLoadedClass(int index) {
+        return classObjects.get(index);
+    }
+
+    /**
+     * Creates new instance of <code>CustomClassLoader</code> class as the current
+     * class loader and clears the list of loaded classes.
+     *
+     * @return created instance of <code>CustomClassLoader</code> class.
+     *
+     * @see #getClassLoader()
+     * @see #setClassLoader(CustomClassLoader)
+     */
+    public CustomClassLoader createClassLoader() {
+        customClassLoader = new CustomClassLoader(this);
+        classObjects.removeAllElements();
+
+        return customClassLoader;
+    }
+
+    /**
+     * Sets new current class loader and clears the list of loaded classes.
+     *
+     * @see #getClassLoader()
+     * @see #createClassLoader()
+     */
+    public void setClassLoader(CustomClassLoader customClassLoader) {
+        this.customClassLoader = customClassLoader;
+        classObjects.removeAllElements();
+        customClassLoader.setClassUnloader(this);
+    }
+
+    /**
+     * Returns current class loader or <i>null</i> if not yet created or set.
+     *
+     * @return class loader object or null.
+     *
+     * @see #createClassLoader()
+     * @see #setClassLoader(CustomClassLoader)
+     */
+    public CustomClassLoader getClassLoader() {
+        return customClassLoader;
+    }
+
+    /**
+     * Loads class for specified class name using current class loader.
+     *
+     * <p>Current class loader should be set and capable to load class using only
+     * given class name. No other information such a location of .class files
+     * is passed to class loader.
+     *
+     * @param className name of class to load
+     *
+     * @throws ClassNotFoundException if no bytecode found for specified class name
+     * @throws Failure if current class loader is not specified;
+     *                 or if class was actually loaded with different class loader
+     *
+     * @see #loadClass(String, String)
+     */
+    public void loadClass(String className) throws ClassNotFoundException {
+
+        if (customClassLoader == null) {
+            throw new Failure("No current class loader defined");
+        }
+
+        Class<?> cls = Class.forName(className, true, customClassLoader);
+
+        // ensure that class was loaded by current class loader
+        if (cls.getClassLoader() != customClassLoader) {
+            throw new Failure("Class was loaded by unexpected class loader: " + cls.getClassLoader());
+        }
+
+        classObjects.add(cls);
+    }
+
+    /**
+     * Loads class from .class file located into specified directory using
+     * current class loader.
+     *
+     * <p>If there is no current class loader, then default class loader
+     * is created using <code>createClassLoader()</code>. Parameter <i>classDir</i>
+     * is passed to class loader using <code>CustomClassLoader.setClassPath()</code>
+     * method before loading class.
+     *
+     * @param className name of class to load
+     * @param classDir path to .class file location
+     *
+     * @throws ClassNotFoundException if no .class file found
+     *          for specified class name
+     * @throws Failure if class was actually loaded with different class loader
+     *
+     * @see #loadClass(String)
+     * @see CustomClassLoader#setClassPath(String)
+     */
+    public void loadClass(String className, String classDir) throws ClassNotFoundException {
+
+        if (customClassLoader == null) {
+            createClassLoader();
+        }
+
+        customClassLoader.setClassPath(classDir);
+        loadClass(className);
+    }
+
+    /**
+     * Forces GC to unload previously loaded classes by cleaning all references
+     * to class loader with its loaded classes and eating memory.
+     *
+     * @return  <i>true</i> if classes unloading has been detected
+             or <i>false</i> otherwise
+     *
+     * @throws  Failure if exception other than OutOfMemoryError
+     *           is thrown while eating memory
+     *
+     * @see #eatMemory()
+     */
+    public boolean unloadClass(ExecutionController stresser) {
+
+        finalized = false;
+
+        // free references to class and class loader to be able for collecting by GC
+        long waitTimeout = (customClassLoader == null) ? 0 : WAIT_TIMEOUT;
+        classObjects.removeAllElements();
+        customClassLoader = null;
+
+        // force class unloading by eating memory pool
+        eatMemory(stresser);
+
+        // give GC chance to run and wait for finalization
+        long timeToFinish = System.currentTimeMillis() + waitTimeout;
+        while (!finalized && System.currentTimeMillis() < timeToFinish) {
+            if (!stresser.continueExecution()) {
+                return false;
+            }
+            try {
+                // suspend thread for a while
+                Thread.sleep(WAIT_DELTA);
+            } catch (InterruptedException e) {
+                throw new Failure("Unexpected InterruptedException while class unloading: " + e);
+            }
+        }
+
+        // force GC to unload marked class loader and its classes
+        if (finalized) {
+            Runtime.getRuntime().gc();
+            return true;
+        }
+
+        // class loader has not been finalized
+        return false;
+    }
+
+    public boolean unloadClass() {
+        Stresser stresser = new Stresser() {
+
+            @Override
+            public boolean continueExecution() {
+                return true;
+            }
+
+        };
+        return unloadClass(stresser);
+    }
+
+    /**
+     * Stresses memory by allocating arrays of bytes.
+     *
+     * Note that this method can throw Failure if any exception
+     * is thrown while eating memory. To avoid OOM while allocating
+     * exception we preallocate it before the lunch starts. It means
+     * that exception stack trace does not correspond to the place
+     * where exception is thrown, but points at start of the method.
+     *
+     * @throws  Failure if exception other than OutOfMemoryError
+     *           is thrown while eating memory
+     */
+    public static void eatMemory(ExecutionController stresser) {
+        GarbageUtils.eatMemory(stresser, 50, 1024, 2);
+
+        /*
+         * System.runFinalization() may potentially fail with OOM. This is why
+         * System.runFinalization() is repeated several times.
+         */
+        for (int i = 0; i < 10; ++i) {
+            try {
+                if(!stresser.continueExecution()) {
+                    return;
+                }
+                System.runFinalization();
+                break;
+            } catch (OutOfMemoryError e) {
+            }
+        }
+    }
+
+        /**
+     * Stresses memory by allocating arrays of bytes.
+     *
+     * Note that this method can throw Failure if any exception
+     * is thrown while eating memory. To avoid OOM while allocating
+     * exception we preallocate it before the lunch starts. It means
+     * that exception stack trace does not correspond to the place
+     * where exception is thrown, but points at start of the method.
+     *
+     * @throws  Failure if exception other than OutOfMemoryError
+     *           is thrown while eating memory
+     */
+    public static void eatMemory() {
+        Stresser stresser = new Stresser() {
+
+            @Override
+            public boolean continueExecution() {
+                return true;
+            }
+
+        };
+        GarbageUtils.eatMemory(stresser, 50, 1024, 2);
+        /*
+         * System.runFinalization() may potentially fail with OOM. This is why
+         * System.runFinalization() is repeated several times.
+         */
+        for (int i = 0; i < 10; ++i) {
+            try {
+                if(!stresser.continueExecution()) {
+                    return;
+                }
+                System.runFinalization();
+                break;
+            } catch (OutOfMemoryError e) {
+            }
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/Consts.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2002, 2018, 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.
+ */
+
+package nsk.share;
+
+/**
+ * This class defines constants
+ *
+ */
+public class Consts {
+
+    /**
+     * Exit code when test passed
+     */
+    public final static int TEST_PASSED = 0;
+
+    /**
+     * Exit code when test failed
+     */
+    public final static int TEST_FAILED = 2;
+
+    /**
+     * Shift of exit code
+     */
+    public final static int JCK_STATUS_BASE = 95;
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/CustomClassLoader.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2003, 2018, 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.
+ */
+
+package nsk.share;
+
+import java.io.*;
+
+/**
+ * The <code>CustomClassLoader</code> class is used in <code>ClassUnloader</code>.
+ *
+ * <p>This class loader can load classes and notify <code>ClassUnloader</code>
+ * about own finalization to make sure that all loaded classes have been unloaded.
+ *
+ * <p>By default this class loader loads class from .class file located in directory
+ * specified with <code>setClassPath()</code> method. To use any other technique
+ * of class loading one should implement derived class, which would override
+ * <code>findClass</code> method.
+ *
+ * @see nsk.share.ClassUnloader
+ *
+ * @see #setClassPath(String)
+ * @see #findClass(String)
+ */
+public class CustomClassLoader extends ClassLoader {
+
+    private ClassUnloader classUnloader;
+    protected String classPath;
+
+    /**
+     * Initializes a newly created <code>CustomClassloader</code> object
+     * not yet linked with any <code>ClassUnloader</code> object.
+     *
+     */
+    public CustomClassLoader() {
+        super(CustomClassLoader.class.getClassLoader());
+        this.classUnloader = null;
+    }
+
+    /**
+     * Initializes a newly created <code>CustomClassloader</code> object
+     * linked with specified <code>ClassUnloader</code> object.
+     *
+     * @param classUnloader an instance of <code>ClassUnloader</code>
+     */
+    public CustomClassLoader(ClassUnloader classUnloader) {
+        super(CustomClassLoader.class.getClassLoader());
+        this.classUnloader = classUnloader;
+    }
+
+    /**
+     * Links this class loader with specified <code>ClassUnloader</code> object.
+     *
+     * @param classUnloader an instance of <code>ClassUnloader</code>
+     */
+    public void setClassUnloader(ClassUnloader classUnloader) {
+        this.classUnloader = classUnloader;
+    }
+
+    /**
+     * Specifies path to .class file location.
+     *
+     * @param classPath a path to .class file location
+     */
+    public void setClassPath(String classPath) {
+        this.classPath = classPath;
+    }
+
+    /**
+     * Finds and loads class for specified class name.
+     * This method loads class from .class file located in a directory
+     * previously specified by <code>setClassPath()</code>.
+     *
+     * @param name The name of the class.
+     *
+     * @throws ClassNotFoundException if no .class file found
+     *          for specified class name
+     *
+     * @see #setClassPath(String)
+     */
+    protected synchronized Class findClass(String name) throws ClassNotFoundException {
+        java.nio.file.Path path = ClassFileFinder.findClassFile(name, classPath);
+        if (path == null) {
+            throw new ClassNotFoundException(name);
+        }
+        String classFileName = path.toString();
+
+        FileInputStream in;
+        try {
+            in = new FileInputStream(classFileName);
+            if (in == null) {
+                throw new ClassNotFoundException(classFileName);
+            }
+        } catch (FileNotFoundException e) {
+            throw new ClassNotFoundException(classFileName, e);
+        }
+
+        int len;
+        byte data[];
+        try {
+            len = in.available();
+            data = new byte[len];
+            for (int total = 0; total < data.length; ) {
+                total += in.read(data, total, data.length - total);
+            }
+        } catch (IOException e) {
+            throw new ClassNotFoundException(classFileName, e);
+        } finally {
+            try {
+                in.close();
+            } catch (IOException e) {
+                throw new ClassNotFoundException(classFileName, e);
+            }
+        }
+
+        return defineClass(name, data, 0, data.length);
+    }
+
+    /**
+     * Notifies <code>ClassUnloader</code> about finalization.
+     */
+    protected void finalize() throws Throwable {
+
+        // notify ClassUnloader about finalization
+        if (classUnloader != null) {
+            classUnloader.finalized = true;
+        }
+
+        super.finalize();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/Debug.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2005, 2018, 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.
+ */
+package nsk.share;
+
+public class Debug
+{
+    // tests assertion to be valid, otherwise FAIL test with message
+    static public void Assert(boolean condition, String message)
+    {
+        if (!condition)
+            Debug.Fail(message);
+    }
+
+    // print message and FAIL test
+    static public void Fail(String message)
+    {
+        System.out.println(message);
+        System.exit(100);
+    }
+
+    static public void Fail(Throwable e)
+    {
+        Fail(e.toString());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/Denotation.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2002, 2018, 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.
+ */
+
+package nsk.share;
+
+import java.util.*;
+
+/**
+ * Denotation implies a pair of algorithms for naming and
+ * indexing of some objects.
+ *
+ * <p>No matter what kind of objects, just make sure that:
+ * <ul>
+ * <li><tt>indexFor(nameFor(index))</tt> equals to <tt>index</tt>
+ * </li>
+ * <li><tt>nameFor(indexFor(name))</tt> is equivalent to <tt>name</tt>
+ * </li>
+ * </ul>
+ *
+ * <p>The notions of indeces equality and names equivalence
+ * are formalized by the methods <tt>equality()</tt> and
+ * <tt>equivalence()</tt> correspondingly.
+ *
+ * <p>For better understanding of Denotation, you may want to
+ * see the TreeNodesDenotation class as an implementation example.
+ *
+ * @see #equality(int[],int[])
+ * @see #equivalence(String,String)
+ * @see TreeNodesDenotation
+ */
+abstract public class Denotation {
+    /**
+     * Check if the <tt>name</tt> is legal, and return the
+     * numeric index for that object denoted by the given
+     * <tt>name</tt>.
+     *
+     * @throws IllegalArgumentException If the <tt>name</tt>
+     * is illegal.
+     */
+    abstract public int[] indexFor(String name);
+
+    /**
+     * Check if the <tt>index[]</tt> is legal, and return
+     * a symbolic name for the object denoted by the given
+     * <tt>index[]</tt>.
+     *
+     * @throws IllegalArgumentException If the <tt>index[]</tt>
+     * is illegal.
+     */
+    abstract public String nameFor(int[] index);
+
+    /**
+     * Re-call to <tt>nameFor(int[])</tt> with the 1-element
+     * array <tt>{i}</tt> as the <tt>index</tt> argument.
+     *
+     * @see #nameFor(int[])
+     */
+    public String nameFor(int i) {
+        return nameFor(new int[] { i });
+    }
+
+    /**
+     * Re-call to <tt>nameFor(int[])</tt> with the 2-elements
+     * array <tt>{i0,i1}</tt> as the <tt>index</tt> argument.
+     *
+     * @see #nameFor(int[])
+     */
+    public String nameFor(int i0, int i1) {
+        return nameFor(new int[] {i0, i1});
+    }
+
+    /**
+     * Re-call to <tt>nameFor(int[])</tt> with the 3-elements
+     * array <tt>{i0,i1,i2}</tt> as the <tt>index</tt> argument.
+     *
+     * @see #nameFor(int[])
+     */
+    public String nameFor(int i0, int i1, int i2) {
+        return nameFor(new int[] {i0, i1, i2});
+    }
+
+    /**
+     * Indeces equality means equality of objects they denote.
+     *
+     * <p>Indeces <tt>index1[]</tt> and <tt>index2[]</tt> are
+     * equal, if they are equal as <tt>int[]</tt> arrays. But,
+     * there is no index equal to <tt>null</tt>; particularly,
+     * <tt>null</tt> is not equal to itself.
+     *
+     * @see Arrays#equals(int[],int[])
+     */
+    public boolean equality(int[] index1, int[] index2) {
+        if (index1 == null || index2 == null)
+            return false;
+        return Arrays.equals(index1,index2);
+    }
+
+    /**
+     * Names equivalence means equality of objects they denote.
+     *
+     * <p>Strings <tt>name1</tt> and <tt>name2</tt> are equivalent,
+     * if correspondent indeces are equal. There is no <tt>name</tt>
+     * equivalent to <tt>null</tt>; particularly, <tt>null</tt> is
+     * not equivalent to itself.
+     *
+     * @see #equality(int[],int[])
+     */
+    public boolean equivalence(String name1, String name2) {
+        if (name1 == null || name2 == null)
+            return false;
+        return equality(indexFor(name1),indexFor(name2));
+    }
+
+    /**
+     * Dummy constructor.
+     */
+    protected Denotation() {
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/DummyClassLoader.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2002, 2018, 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.
+ */
+
+package nsk.share;
+
+/**
+ * This loader's <tt>findClass()</tt> method is dummy.
+ */
+public class DummyClassLoader extends ClassLoader {
+    /**
+     * Cannot instantiate w/o a parent loader.
+     */
+    protected DummyClassLoader() {
+    }
+
+    /**
+     * Delegate everything to the <tt>parent</tt> loader.
+     */
+    public DummyClassLoader(ClassLoader parent) {
+        super(parent);
+    }
+
+    /**
+     * Do nothing: parent loader must load everything.
+     *
+     * @throws ClassNotFoundException In any case.
+     */
+    public Class findClass(String name) throws ClassNotFoundException {
+        throw new ClassNotFoundException(name);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/Failure.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2001, 2018, 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.
+ */
+
+package nsk.share;
+
+import java.io.*;
+
+/**
+ * Thrown to indicate failure caused by some occasional reason,
+ * which does not indicate a problem in the JVM being tested.
+ */
+public class Failure extends RuntimeException {
+        /** Enwrap another throwable. */
+        public Failure(Throwable throwable) {
+                super(throwable);
+        }
+
+        /** Explain particular failure. */
+        public Failure(String message) {
+                super(message);
+        }
+
+        public Failure(String message, Throwable cause) {
+                super(message, cause);
+        }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/FileUtils.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2007, 2018, 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.
+ */
+
+package nsk.share;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.FileInputStream;
+
+public class FileUtils {
+        private FileUtils() {
+        }
+
+        /**
+         * Read whole file.
+         *
+         * @param file file
+         * @return contents of file as byte array
+         */
+        public static byte[] readFile(File file) throws IOException {
+                InputStream in = new FileInputStream(file);
+                long countl = file.length();
+                if (countl > Integer.MAX_VALUE)
+                        throw new IOException("File is too huge");
+                int count = (int) countl;
+                byte[] buffer = new byte[count];
+                int n = 0;
+                try {
+                        while (n < count) {
+                                int k = in.read(buffer, n, count - n);
+                                if (k < 0)
+                                        throw new IOException("Unexpected EOF");
+                                n += k;
+                        }
+                } finally {
+                        in.close();
+                }
+                return buffer;
+        }
+
+        /**
+         * Read whole file.
+         *
+         * @param name file name
+         * @return contents of file as byte array
+         */
+        public static byte[] readFile(String name) throws IOException {
+                return readFile(new File(name));
+        }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/Finalizable.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2001, 2018, 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.
+ */
+
+package nsk.share;
+
+/**
+ * Finalizable interface allows <tt>Finalizer</tt> to perform finalization of an object.
+ * Each object that requires finalization at VM shutdown time should implement this
+ * interface and activate a <tt>Finalizer</tt> hook.
+ *
+ * @see Finalizer
+ */
+public interface Finalizable {
+
+    /**
+     * This method will be invoked by <tt>Finalizer</tt> when virtual mashine
+     * shuts down.
+     *
+     * @throws Throwable if any throwable exception thrown during finalization
+     */
+    public void finalizeAtExit() throws Throwable;
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/FinalizableObject.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2001, 2018, 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.
+ */
+
+package nsk.share;
+
+/**
+ * This class is an simple exalmple of finalizable object, that implements interface
+ * <code>Finalizable</code> and invokes standard <code>finalize()</code> method
+ * as finalization.
+ *
+ * @see Finalizable
+ * @see Finalizer
+ */
+public class FinalizableObject implements Finalizable {
+
+    /**
+     * This method will be invoked by <tt>Finalizer</tt> when virtual mashine
+     * shuts down.
+     * For <code>FinalizableObject</code> this method just invoke
+     * <code>finalize()</code>.
+     *
+     * @throws Throwable if any throwable exception thrown during finalization
+     *
+     * @see Object#finalize()
+     * @see Finalizer
+     */
+    public void finalizeAtExit() throws Throwable {
+        finalize();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/Finalizer.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2001, 2018, 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.
+ */
+
+package nsk.share;
+
+import java.util.Stack;
+
+/**
+ * Finalizer performs object finalization when virtual mashine shuts down.
+ * Finalizer is a thread that acts as a VM shutdown hook.
+ * This thread will be activated as VM shuts down because of
+ * invocation of <code>exit()</code> or termination. After activation
+ * Finalizer just calls <code>finalizeAtExit()</code> method of the specified object.
+ * The finalizable object should implement interface <code>Finalizable</code>.
+ *
+ * @see Finalizable
+ */
+public class Finalizer {
+
+    /** Finalizer thread to register as a VM shutdown hook. */
+    private static FinalizerThread finalizerThread = null;
+
+    /** An object to finalize. */
+    private Finalizable object;
+
+    /**
+     * Create finalizer for the specified object.
+     */
+    public Finalizer(Finalizable object) {
+        this.object = object;
+    }
+
+    /**
+     * Register finalizer for finalization at VM shutdown.
+     */
+    public void activate() {
+        if (finalizerThread == null) {
+            finalizerThread = new FinalizerThread("FinalizerThread for Finalizable objects");
+            finalizerThread.activate();
+        }
+        finalizerThread.add(object);
+    }
+
+    /**
+     * Unregister finalizer for finalization at VM shutdown.
+     */
+    public void deactivate() {
+        if (finalizerThread == null)
+            return;
+        finalizerThread.remove(object);
+    }
+
+    /**
+     * Static inner thread that is registered as a VM shutdown hook
+     * and performs finalization of all registered finalizable objects.
+     */
+    private static class FinalizerThread extends Thread {
+
+        /** Stack of objects registered for finalization. */
+        private Stack<Object> objects = new Stack<Object>();
+
+        /** Make new instance of FinalizerThread with given thread name. */
+        public FinalizerThread(String threadName) {
+            super(threadName);
+        }
+
+        /**
+         * Push an object to the stack of registered objects.
+         */
+        public void add(Finalizable object) {
+            objects.push(object);
+        }
+
+        /**
+         * Remove an object from the stack of registered objects.
+         */
+        public void remove(Finalizable object) {
+            objects.remove(object);
+        }
+
+        /**
+         * Register finalizer thread as a VM shutdown hook.
+         */
+        public void activate() {
+            Runtime.getRuntime().addShutdownHook( this );
+        }
+
+        /**
+         * Unregister finalizer thread as a VM shutdown hook.
+         */
+        public void deactivate() {
+            Runtime.getRuntime().removeShutdownHook( this );
+        }
+
+        /**
+         * Pop all registered objects from the stack and finalize them.
+         */
+        public void run() {
+            while (!objects.empty()) {
+                Finalizable object = (Finalizable)objects.pop();
+                try {
+                    object.finalizeAtExit();
+                } catch (ThreadDeath e) {
+                    throw e;
+                } catch (Throwable ex) {
+                    ex.printStackTrace();
+                }
+            }
+        }
+
+    } // end of FinalizerThread
+
+} // end of Finalizer
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/GoldChecker.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2008, 2018, 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.
+ */
+package nsk.share;
+
+import java.io.*;
+
+public class GoldChecker extends AbstractGoldChecker
+{
+    private final String goldOutput;
+
+    public GoldChecker(String main_class_name) {
+        goldOutput = readGoldStr(main_class_name + ".gold");
+    }
+
+    @Override
+    protected String getGoldenString() {
+        return goldOutput;
+    }
+
+    private String readGoldStr(String gold_file_name) {
+        RandomAccessFile f;
+
+        try {
+            f = new RandomAccessFile(gold_file_name, "r");
+        } catch (FileNotFoundException e) {
+            throw new TestBug("Unable to open golden file '" + gold_file_name + "' for reading");
+        }
+
+        byte[] data;
+
+        try {
+            int len = (int)f.length();
+            data = new byte[len];
+            f.read(data);
+        } catch (IOException e) {
+            throw new TestBug("Error reading from golden file'" + gold_file_name + "'");
+        }
+
+        try {
+            f.close();
+        } catch (IOException e) {
+        }
+
+        try {
+            return new String(data, "US-ASCII");
+        } catch (UnsupportedEncodingException e) {
+            throw new TestFailure( e );
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/Grep.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2002, 2018, 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.
+ */
+
+package nsk.share;
+
+import java.util.*;
+import java.util.regex.*;
+
+/**
+ * Emulator of perl's grep function.
+ * This class uses java.util.regexp classes which appear in
+ * JDK1.4 API. This implies the restriction for this class
+ * to not be used with the tests against JDKs prior to 1.4.
+ *
+ * @see java.util.regex.Pattern
+ * @see java.util.regex.Matcher
+ */
+
+public class Grep {
+
+    String[] stringArray;
+    /**
+     * Takes String array as character sequence for matching the pattern.
+     */
+    public Grep (String[] stringArray) {
+        this.stringArray = stringArray;
+    }
+
+    /**
+     * Returns number of non-interleaved occurences of groups which match the pattern.
+     */
+    public int find (String regExpPattern) {
+        if (regExpPattern.length() == 0) {
+            throw new Failure("Empty string as input parameter for Grep.find(regExpPattern) method");
+        }
+        Pattern pattern = Pattern.compile(regExpPattern);
+        int counter = 0;
+        for (int i = 0; i < stringArray.length; i++) {
+
+            String string = stringArray[i];
+            if (string != null) {
+                // Create matcher for this string
+                Matcher matcher = pattern.matcher(string);
+
+                // Find all non-interleaved occurences of pattern in this string
+                for (int ind = 0; ind < string.length(); ) {
+                    if (matcher.find(ind)) {
+                       counter++;
+                       ind = matcher.end();
+                    } else {
+                       break;
+                    }
+                }
+            }
+        }
+        return counter;
+    }
+
+    /**
+     * Returns first string of stringArray with group which matches
+     * the pattern or empty string othrewise.
+     */
+    public String findFirst (String regExpPattern) {
+        if (regExpPattern.length() == 0) {
+            throw new Failure("Empty string as input parameter for Grep.findFirst(regExpPattern) method");
+        }
+        Pattern pattern = Pattern.compile(regExpPattern);
+        String result = "";
+        for (int i = 0; i < stringArray.length; i++) {
+
+            String string = stringArray[i];
+            if (string != null) {
+                // Create matcher for this string
+                Matcher matcher = pattern.matcher(string);
+                if (matcher.find()) {
+                    result = string;
+                    break;
+                }
+            }
+        }
+        return result;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/Harakiri.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,175 @@
+/*
+ * Copyright (c) 2001, 2018, 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.
+ */
+
+package nsk.share;
+
+/**
+ * Harakiri is used to terminate a stress test with PASS exit status
+ * before the test is terminated as timed out (and so failed).
+ *
+ * <p>Harakiri class holds a thread which sleeps for the given amount
+ * of time, and then wakes up and executes <tt>System.exit()</tt>
+ * with the given exit status. That thread is daemon, so it doesn't
+ * prevent application from exiting once all its threads finish
+ * before it's time for harakiri. Appointing harakiri in zero
+ * delay implies immediate <tt>exit()</tt>.
+ *
+ * <p>There is a limitation: you may appoint no more than one harakiri
+ * per application.
+ */
+public class Harakiri {
+    /**
+     * Use specific <tt>appoint()</tt> method to appoint harakiri.
+     *
+     * @see #appoint(int)
+     * @see #appoint(int,int)
+     */
+    protected Harakiri() {}
+
+    /**
+     * One harakiri per application, or <tt>null</tt> (by default).
+     */
+    private static Thread harakiri = null;
+
+    /**
+     * <p>Return timeout (or waittime) value munus the margin
+     * value (which is assumed 1 minute by default).
+     *
+     * <p>Treat <tt>args[0]</tt> as <tt>$TIMEOUT</tt> value, or seek for
+     * <tt>-waittime=$WAITTIME</tt> value. If both parameters
+     * (or either none of them) are assigned, throw an exception to
+     * report parameters inconsistency.
+     *
+     * <p>Also, seek for <tt>-margin=...</tt> assignment, or assume margin
+     * is 1 minute.
+     *
+     * @param args Is usually obtained via the application's command-line.
+     *
+     * @throws IllegalArgumentException If <tt>args[]</tt> is inconsistent.
+     *
+     * @see #appoint(int)
+     * @see #appoint(int,int)
+     */
+    public static int parseAppointment(String args[]) {
+        int timeout=-1, margin=1;
+        int timeouts=0, waittimes=0, margins=0;
+        for (int i=0; i<args.length; i++) {
+            if (args[i].startsWith("-")) {
+                if (args[i].startsWith("-waittime=")) {
+                    timeout = Integer.parseInt(args[i].substring(10));
+                    waittimes++;
+                }
+                if (args[i].startsWith("-margin=")) {
+                    margin = Integer.parseInt(args[i].substring(8));
+                    margins++;
+                }
+            } else {
+                if (i == 0) {
+                    timeout = Integer.parseInt(args[i]);
+                    timeouts++;
+                }
+            }
+        };
+        if (timeouts==0 && waittimes==0)
+            throw new IllegalArgumentException(
+                "no $TIMEOUT, nor -waittime=$WAITTIME is set");
+        if (waittimes > 1)
+            throw new IllegalArgumentException(
+                "more than one -waittime=... is set");
+        if (margins > 1)
+            throw new IllegalArgumentException(
+                "more than one -margin=... is set");
+
+        int result = timeout - margin;
+        if (result <= 0)
+            throw new IllegalArgumentException(
+                "delay appointment must be greater than "+margin+" minutes");
+        return result;
+    }
+
+    /**
+     * Appoint harakiri after the given amount of <tt>minutes</tt>,
+     * so that exit status would be 95 (to simulate JCK-like PASS
+     * status).
+     *
+     * @throws IllegalStateException If harakiri is already appointed.
+     *
+     * @see #appoint(int,int)
+     * @see #parseAppointment(String[])
+     */
+    public static void appoint(int minutes) {
+        appoint(minutes,95); // JCK-like PASS status
+    }
+
+    /**
+     * Appoint Harakiri for the given amount of <tt>minutes</tt>,
+     * so that the given <tt>status</tt> would be exited when time
+     * is over.
+     *
+     * @throws IllegalStateException If harakiri is already appointed.
+     *
+     * @see #appoint(int)
+     * @see #parseAppointment(String[])
+     */
+    public static void appoint(int minutes, int status) {
+        if (harakiri != null)
+            throw new IllegalStateException("Harakiri is already appointed.");
+
+        final long timeToExit = System.currentTimeMillis() + 60*1000L*minutes;
+        final int  exitStatus = status;
+
+        harakiri = new Thread(Harakiri.class.getName()) {
+            public void run() {
+                long timeToSleep = timeToExit - System.currentTimeMillis();
+                if (timeToSleep > 0)
+                    try {
+                        //
+                        // Use wait() instead of sleep(), because Java 2
+                        // specification doesn't guarantee the method
+                        // sleep() to yield to other threads.
+                        //
+                        Object someDummyObject = new Object();
+                        synchronized (someDummyObject) {
+                            someDummyObject.wait(timeToSleep);
+                        }
+                    } catch (InterruptedException exception) {
+                        exception.printStackTrace(System.err);
+                       //
+                       // OOPS, the dagger for harakiri looks broken:
+                       //
+                       return;
+                    };
+                //
+                // OK, lets do it now:
+                //
+                System.err.println(
+                    "#\n# Harakiri: prescheduled program termination.\n#");
+                System.exit(exitStatus); // harakiri to all threads
+            }
+        };
+
+        harakiri.setPriority(Thread.MAX_PRIORITY);
+        harakiri.setDaemon(true);
+        harakiri.start();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/IORedirector.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2001, 2018, 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.
+ */
+
+package nsk.share;
+
+import java.io.*;
+
+/**
+ * This class implements a thread transfering bytes from
+ * a given InputStream to a given OutputStream.
+ */
+public class IORedirector extends Thread {
+    private BufferedReader bin  = null;
+    private PrintStream    pout = null;
+    private Log            log  = null;
+
+    /**
+     * Few symbols to precede every text line being redirected.
+     */
+    private String prefix = "";
+
+    /**
+     * Input and output streams must be specified.
+     */
+    private IORedirector() {
+        super("IORedirector");
+    }
+
+    /**
+     * Redirect <code>in</code> to <code>out</code>.
+     *
+     * @deprecated Use newer constructor.
+     *
+     * @see #IORedirector(BufferedReader,Log,String)
+     */
+    public IORedirector(InputStream in, OutputStream out) {
+        this();
+        bin  = new BufferedReader(new InputStreamReader(in));
+        pout = new PrintStream(out);
+    }
+
+    /**
+     * Redirect <code>in</code> to <code>log</code>; and assign
+     * few <code>prefix</code> symbols to precede each text line
+     * being redirected.
+     */
+    public IORedirector(BufferedReader in, Log log, String prefix) {
+        this();
+        this.prefix = prefix;
+        this.bin  = in;
+        this.log = log;
+    }
+
+    /**
+     * Set the prefix for redirected messages;
+     */
+    public void setPrefix(String prefix) {
+        this.prefix = prefix;
+    }
+
+    private boolean cancelled = false;
+    private boolean stopped = false;
+    private boolean started = false;
+
+    /**
+     * Signal to <code>run()</code> method that it should terminate,
+     * and wait until it is finished.
+     */
+    public void cancel () {
+        cancelled = true;
+        while (this.isAlive())
+            try {
+                this.join();
+            } catch (InterruptedException ie) {
+                throw new Failure(ie);
+            };
+        // stopped==true here.
+    }
+
+    /**
+     * Pass data bytes from <code>in</code> to <code>out</code> stream
+     * until EOF is read, or this IORedirector is cancelled.
+     */
+    public void run () {
+        started = true;
+        String logPrefix = "IORedirector-" + prefix;
+        if (bin == null || (pout == null && log == null))
+            return;
+        try {
+            while (!cancelled) {
+                String line = bin.readLine();
+                if (line == null)
+                    break; //EOF
+                String message = prefix + line;
+                if (log != null) {
+                    // It's synchronized and auto-flushed:
+                    log.println(message);
+                } else if (pout != null) {
+                    synchronized (pout) {
+                        pout.println(message);
+                        pout.flush();
+                    }
+                }
+            }
+        } catch (IOException e) {
+            // e.printStackTrace(log.getOutStream());
+            String msg = "# WARNING: Caught IOException while redirecting output stream:\n\t" + e;
+            if (log != null) {
+                log.println(msg);
+            } else if (pout != null) {
+                synchronized (pout) {
+                    pout.println(msg);
+                    pout.flush();
+                }
+            } else {
+                System.err.println(msg);
+                System.err.flush();
+            }
+        };
+        stopped = true;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/JVMDITools.c	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 2001, 2018, 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.
+ */
+
+#include "jvmdi.h"
+#include "JVMDITools.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+char const *TranslateEvent(jint kind) {
+    switch (kind) {
+    case JVMDI_EVENT_SINGLE_STEP:
+        return ("JVMDI_EVENT_SINGLE_STEP");
+    case JVMDI_EVENT_BREAKPOINT:
+        return ("JVMDI_EVENT_BREAKPOINT");
+    case JVMDI_EVENT_FRAME_POP:
+        return ("JVMDI_EVENT_FRAME_POP");
+    case JVMDI_EVENT_EXCEPTION:
+        return ("JVMDI_EVENT_EXCEPTION");
+    case JVMDI_EVENT_USER_DEFINED:
+        return ("JVMDI_EVENT_USER_DEFINED");
+    case JVMDI_EVENT_THREAD_START:
+        return ("JVMDI_EVENT_THREAD_START");
+    case JVMDI_EVENT_THREAD_END:
+        return ("JVMDI_EVENT_THREAD_END");
+    case JVMDI_EVENT_CLASS_PREPARE:
+        return ("JVMDI_EVENT_CLASS_PREPARE");
+    case JVMDI_EVENT_CLASS_UNLOAD:
+        return ("JVMDI_EVENT_CLASS_UNLOAD");
+    case JVMDI_EVENT_CLASS_LOAD:
+        return ("JVMDI_EVENT_CLASS_LOAD");
+    case JVMDI_EVENT_FIELD_ACCESS:
+        return ("JVMDI_EVENT_FIELD_ACCESS");
+    case JVMDI_EVENT_FIELD_MODIFICATION:
+        return ("JVMDI_EVENT_FIELD_MODIFICATION");
+    case JVMDI_EVENT_EXCEPTION_CATCH:
+        return ("JVMDI_EVENT_EXCEPTION_CATCH");
+    case JVMDI_EVENT_METHOD_ENTRY:
+        return ("JVMDI_EVENT_METHOD_ENTRY");
+    case JVMDI_EVENT_METHOD_EXIT:
+        return ("JVMDI_EVENT_METHOD_EXIT");
+    case JVMDI_EVENT_VM_INIT:
+        return ("JVMDI_EVENT_VM_INIT");
+    case JVMDI_EVENT_VM_DEATH:
+        return ("JVMDI_EVENT_VM_DEATH");
+    default:
+        return ("<Unknown Event>");
+    }
+}
+
+char const *TranslateError(jvmdiError err) {
+    switch (err) {
+    case JVMDI_ERROR_NONE:
+        return ("JVMDI_ERROR_NONE");
+    case JVMDI_ERROR_OUT_OF_MEMORY:
+        return ("JVMDI_ERROR_OUT_OF_MEMORY");
+    case JVMDI_ERROR_ACCESS_DENIED:
+        return ("JVMDI_ERROR_ACCESS_DENIED");
+    case JVMDI_ERROR_UNATTACHED_THREAD:
+        return ("JVMDI_ERROR_UNATTACHED_THREAD");
+    case JVMDI_ERROR_VM_DEAD:
+        return ("JVMDI_ERROR_VM_DEAD");
+    case JVMDI_ERROR_INTERNAL:
+        return ("JVMDI_ERROR_INTERNAL");
+    case JVMDI_ERROR_INVALID_THREAD:
+        return ("JVMDI_ERROR_INVALID_THREAD");
+    case JVMDI_ERROR_INVALID_FIELDID:
+        return ("JVMDI_ERROR_INVALID_FIELDID");
+    case JVMDI_ERROR_INVALID_METHODID:
+        return ("JVMDI_ERROR_INVALID_METHODID");
+    case JVMDI_ERROR_INVALID_LOCATION:
+        return ("JVMDI_ERROR_INVALID_LOCATION");
+    case JVMDI_ERROR_INVALID_FRAMEID:
+        return ("JVMDI_ERROR_INVALID_FRAMEID");
+    case JVMDI_ERROR_NO_MORE_FRAMES:
+        return ("JVMDI_ERROR_NO_MORE_FRAMES");
+    case JVMDI_ERROR_OPAQUE_FRAME:
+        return ("JVMDI_ERROR_OPAQUE_FRAME");
+    case JVMDI_ERROR_NOT_CURRENT_FRAME:
+        return ("JVMDI_ERROR_NOT_CURRENT_FRAME");
+    case JVMDI_ERROR_TYPE_MISMATCH:
+        return ("JVMDI_ERROR_TYPE_MISMATCH");
+    case JVMDI_ERROR_INVALID_SLOT:
+        return ("JVMDI_ERROR_INVALID_SLOT");
+    case JVMDI_ERROR_DUPLICATE:
+        return ("JVMDI_ERROR_DUPLICATE");
+    case JVMDI_ERROR_THREAD_NOT_SUSPENDED:
+        return ("JVMDI_ERROR_THREAD_NOT_SUSPENDED");
+    case JVMDI_ERROR_THREAD_SUSPENDED:
+        return ("JVMDI_ERROR_THREAD_SUSPENDED");
+    case JVMDI_ERROR_INVALID_OBJECT:
+        return ("JVMDI_ERROR_INVALID_OBJECT");
+    case JVMDI_ERROR_INVALID_CLASS:
+        return ("JVMDI_ERROR_INVALID_CLASS");
+    case JVMDI_ERROR_CLASS_NOT_PREPARED:
+        return ("JVMDI_ERROR_CLASS_NOT_PREPARED");
+    case JVMDI_ERROR_NULL_POINTER:
+        return ("JVMDI_ERROR_NULL_POINTER");
+    case JVMDI_ERROR_ABSENT_INFORMATION:
+        return ("JVMDI_ERROR_ABSENT_INFORMATION");
+    case JVMDI_ERROR_INVALID_EVENT_TYPE:
+        return ("JVMDI_ERROR_INVALID_EVENT_TYPE");
+    case JVMDI_ERROR_NOT_IMPLEMENTED:
+        return ("JVMDI_ERROR_NOT_IMPLEMENTED");
+    case JVMDI_ERROR_INVALID_THREAD_GROUP:
+        return ("JVMDI_ERROR_INVALID_THREAD_GROUP");
+    case JVMDI_ERROR_INVALID_PRIORITY:
+        return ("JVMDI_ERROR_INVALID_PRIORITY");
+    case JVMDI_ERROR_NOT_FOUND:
+        return ("JVMDI_ERROR_NOT_FOUND");
+    case JVMDI_ERROR_INVALID_MONITOR:
+        return ("JVMDI_ERROR_INVALID_MONITOR");
+    case JVMDI_ERROR_ILLEGAL_ARGUMENT:
+        return ("JVMDI_ERROR_ILLEGAL_ARGUMENT");
+    case JVMDI_ERROR_NOT_MONITOR_OWNER:
+        return ("JVMDI_ERROR_NOT_MONITOR_OWNER");
+    case JVMDI_ERROR_INTERRUPT:
+        return ("JVMDI_ERROR_INTERRUPT");
+    case JVMDI_ERROR_INVALID_TYPESTATE:
+        return ("JVMDI_ERROR_INVALID_TYPESTATE");
+    case JVMDI_ERROR_INVALID_CLASS_FORMAT:
+        return ("JVMDI_ERROR_INVALID_CLASS_FORMAT");
+    case JVMDI_ERROR_CIRCULAR_CLASS_DEFINITION:
+        return ("JVMDI_ERROR_CIRCULAR_CLASS_DEFINITION");
+    case JVMDI_ERROR_ADD_METHOD_NOT_IMPLEMENTED:
+        return ("JVMDI_ERROR_ADD_METHOD_NOT_IMPLEMENTED");
+    case JVMDI_ERROR_SCHEMA_CHANGE_NOT_IMPLEMENTED:
+        return ("JVMDI_ERROR_SCHEMA_CHANGE_NOT_IMPLEMENTED");
+    case JVMDI_ERROR_FAILS_VERIFICATION:
+        return ("JVMDI_ERROR_FAILS_VERIFICATION");
+#ifdef JVMDI_VERSION_1_2
+    case JVMDI_ERROR_UNSUPPORTED_VERSION:
+        return ("JVMDI_ERROR_UNSUPPORTED_VERSION");
+    case JVMDI_ERROR_HIERARCHY_CHANGE_NOT_IMPLEMENTED:
+        return ("JVMDI_ERROR_HIERARCHY_CHANGE_NOT_IMPLEMENTED");
+    case JVMDI_ERROR_DELETE_METHOD_NOT_IMPLEMENTED:
+        return ("JVMDI_ERROR_DELETE_METHOD_NOT_IMPLEMENTED");
+    case JVMDI_ERROR_NAMES_DONT_MATCH:
+        return ("JVMDI_ERROR_NAMES_DONT_MATCH");
+    case JVMDI_ERROR_CLASS_MODIFIERS_CHANGE_NOT_IMPLEMENTED:
+        return ("JVMDI_ERROR_CLASS_MODIFIERS_CHANGE_NOT_IMPLEMENTED");
+    case JVMDI_ERROR_METHOD_MODIFIERS_CHANGE_NOT_IMPLEMENTED:
+        return ("JVMDI_ERROR_METHOD_MODIFIERS_CHANGE_NOT_IMPLEMENTED");
+#endif
+    default:
+        return ("<Unknown Error>");
+    }
+}
+
+#ifdef __cplusplus
+}
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/JVMDITools.h	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2001, 2018, 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.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+char const *TranslateEvent(jint kind);
+char const *TranslateError(jvmdiError err);
+
+#ifdef __cplusplus
+}
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/JVMTIagent.c	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,1276 @@
+/*
+ * Copyright (c) 2004, 2018, 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.
+ */
+
+/*
+ *
+ * JVMTI agent used for run every test from the testbase in a special
+ * debug mode. This mode is intended to be part of serviceability
+ * reliability testing.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <jvmti.h>
+
+#include "nsk_tools.h"
+#include "jni_tools.h"
+#include "JVMTITools.h"
+#include "jvmti_tools.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static jvmtiEnv *jvmti = NULL; /* JVMTI env */
+static jvmtiEventCallbacks callbacks;
+static jrawMonitorID eventLock; /* raw monitor used for exclusive ownership of HotSwap function */
+
+static volatile int debug_mode = 0; /* 0 - verbose mode off;
+                                       1 - verbose mode on;
+                                       2 - verbose mode on including all JVMTI events reporting,
+                                           produces a huge number of messages */
+
+/* stress level */
+static volatile int stress_lev = 0; /* 0 - default mode: generation of all events except
+                                                ExceptionCatch,
+                                                MethodEntry/Exit, SingleStep;
+                                       1 - generation of all events except
+                                                MethodEntry/Exit,
+                                                SingleStep;
+                                       2 - generation of all events except
+                                                SingleStep;
+                                       3 - generation of all events, including
+                                                ExceptionCatch,
+                                                MethodEntry/Exit,
+                                                SingleStep
+                                     */
+
+#define TRUE 1
+#define FALSE 0
+
+/**** the following is used for "postVM_DEATH" events watching ****/
+static volatile int vm_death_occured = FALSE;
+/************************************************/
+
+/**** the following is used for HotSwap mode ****/
+
+/* HotSwap modes:
+ HOTSWAP_OFF                - default mode: HotSwap off;
+ HOTSWAP_EVERY_METHOD_ENTRY - HotSwap tested class in every method entry event
+                              of running test
+ HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS - HotSwap tested class in every
+                              method entry event of every class
+ HOTSWAP_EVERY_SINGLE_STEP  - HotSwap tested class in every single step event
+                              of running test
+ HOTSWAP_EVERY_EXCEPTION    - HotSwap tested class in every exception event
+                              of running test
+ HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS - HotSwap tested class in every
+                              exception event of every class
+ */
+
+#define HOTSWAP_OFF 0
+#define HOTSWAP_EVERY_METHOD_ENTRY 2
+#define HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS 20
+#define HOTSWAP_EVERY_SINGLE_STEP 3
+#define HOTSWAP_EVERY_EXCEPTION 4
+#define HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS 40
+
+static int hotswap = HOTSWAP_OFF;
+
+typedef struct {   /* test class info */
+    char *clazzsig;  /* class signature */
+    jclass cls;      /* a class to be redefined */
+    jint bCount;     /* number of bytes defining the class */
+    jbyte *clsBytes; /* bytes defining the class */
+    struct class_info *next;
+} class_info;
+
+
+static const char *shortTestName = NULL; /* name of the test without package prefix */
+static jclass rasCls; /* reference to the auxiliary class RASagent used for HotSwap */
+static class_info *clsInfo = NULL, *clsInfoFst = NULL;
+
+static void lock(JNIEnv*);
+static void unlock(JNIEnv*);
+static jint allocClsInfo(JNIEnv*, char*, jclass);
+static void deallocClsInfo(JNIEnv*);
+static int findAndHotSwap(JNIEnv*, jclass);
+static int doHotSwap(JNIEnv*, jclass, jint, jbyte*);
+static void display(int, const char format[], ...);
+static void clearJavaException(JNIEnv*);
+static int enableEventsCaps();
+static int addStressEvents();
+static void getVerdict(JNIEnv*, const char *);
+/************************************************/
+
+/** callback functions **/
+void JNICALL
+Breakpoint(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thr, jmethodID method,
+        jlocation loc) {
+
+    display(1, "#### JVMTIagent: Breakpoint occurred ####\n");
+
+    getVerdict(jni_env, "Breakpoint");
+}
+
+void JNICALL
+ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *jni_env,
+        jclass class_beeing_redefined,
+        jobject loader, const char* name, jobject protection_domain,
+        jint class_data_len, const unsigned char* class_data,
+        jint *new_class_data_len, unsigned char** new_class_data) {
+
+    display(1, "#### JVMTIagent: ClassFileLoadHook occurred ####\n");
+
+    getVerdict(jni_env, "ClassFileLoadHook");
+}
+
+void JNICALL
+ClassLoad(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thread, jclass klass) {
+    char *cls_sig;
+    jint clsByteCount;
+
+    display((hotswap != HOTSWAP_OFF)?0:1,
+        "#### JVMTIagent: ClassLoad occurred ####\n");
+
+    getVerdict(jni_env, "ClassLoad");
+
+    if (hotswap != HOTSWAP_OFF) {
+        /* enter into a raw monitor for exclusive work with redefined class */
+        lock(jni_env);
+        display(0, "#### JVMTIagent: ClassLoad: >>>>>>>> entered the raw monitor \"eventLock\" ####\n");
+
+        if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature,
+                jvmti_env, klass, &cls_sig, /*&generic*/NULL)))
+            NSK_CPP_STUB2(FatalError, jni_env,
+                "JVMTIagent: failed to get class signature\n");
+        else {
+            if (shortTestName != NULL) {
+                if (strstr((const char*) cls_sig, shortTestName) != NULL) {
+                    display(0, "#### JVMTIagent: found test class matched with \"%s\"\n\
+<JVMTIagent>\tsignature=%s\n",
+                        shortTestName, cls_sig);
+                    clsByteCount = allocClsInfo(jni_env, cls_sig, klass);
+                    display(0, "#### JVMTIagent: %d bytes defining the class have been successfully loaded\n",
+                        clsByteCount);
+                }
+            }
+        }
+
+        /* exit from the raw monitor */
+        unlock(jni_env);
+        display(0, "#### JVMTIagent: ClassLoad: <<<<<<<< exited from the raw monitor \"eventLock\" ####\n\n");
+    }
+}
+
+void JNICALL
+ClassPrepare(jvmtiEnv *jvmti_env, JNIEnv *jni_env,
+        jthread thr, jclass cls) {
+
+    display(1, "#### JVMTIagent: ClassPrepare occurred ####\n");
+
+    getVerdict(jni_env, "ClassPrepare");
+}
+
+void JNICALL
+CompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size,
+        const void* code_addr,  jint map_length,
+        const jvmtiAddrLocationMap* map, const void* compile_info) {
+
+    display(1, "#### JVMTIagent: CompiledMethodLoad occurred ####\n");
+
+    getVerdict(NULL, "CompiledMethodLoad");
+}
+
+void JNICALL
+CompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method,
+        const void* code_addr) {
+
+    display(1, "#### JVMTIagent: CompiledMethodUnload occurred ####\n");
+
+    getVerdict(NULL, "CompiledMethodUnload");
+}
+
+void JNICALL
+DataDumpRequest(jvmtiEnv *jvmti_env) {
+
+    display(1, "#### JVMTIagent: DataDumpRequest occurred ####\n");
+
+    getVerdict(NULL, "DataDumpRequest");
+}
+
+void JNICALL
+DynamicCodeGenerated(jvmtiEnv *jvmti_env,
+        const char* name,
+        const void* address,
+        jint length) {
+
+    display(1, "#### JVMTIagent: DynamicCodeGenerated occurred ####\n");
+
+    getVerdict(NULL, "DynamicCodeGenerated");
+}
+
+void JNICALL
+Exception(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thr,
+        jmethodID method, jlocation location, jobject exception,
+        jmethodID catch_method, jlocation catch_location) {
+    jclass decl_clazz;
+
+    display((hotswap == HOTSWAP_EVERY_EXCEPTION ||
+            hotswap == HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS)?0:1,
+        "#### JVMTIagent: Exception occurred ####\n");
+
+    getVerdict(jni_env, "Exception");
+
+    if (hotswap == HOTSWAP_EVERY_EXCEPTION ||
+            hotswap == HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS) {
+        if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass,
+                jvmti_env, method, &decl_clazz)))
+            NSK_CPP_STUB2(FatalError, jni_env,
+                "JVMTIagent: failed to get method declaring class\n");
+
+        if (findAndHotSwap(jni_env, decl_clazz) != 0)
+            NSK_CPP_STUB2(FatalError, jni_env,
+                "JVMTIagent: failed to hotswap class\n");
+    }
+}
+
+void JNICALL
+FieldAccess(jvmtiEnv *jvmti_env, JNIEnv *jni_env,
+        jthread thr, jmethodID method,
+        jlocation location, jclass field_klass, jobject obj, jfieldID field) {
+
+    display(1, "#### JVMTIagent: FieldAccess occurred ####\n");
+
+    getVerdict(jni_env, "FieldAccess");
+}
+
+void JNICALL
+FieldModification(jvmtiEnv *jvmti_env, JNIEnv *jni_env,
+        jthread thr, jmethodID method, jlocation location,
+        jclass field_klass, jobject obj,
+        jfieldID field, char sig, jvalue new_value) {
+
+    display(1, "#### JVMTIagent: FieldModification occurred ####\n");
+
+    getVerdict(jni_env, "FieldModification");
+}
+
+void JNICALL
+FramePop(jvmtiEnv *jvmti_env, JNIEnv *jni_env,
+        jthread thr, jmethodID method, jboolean wasPopedByException) {
+
+    display(1, "#### JVMTIagent: FramePop occurred ####\n");
+
+    getVerdict(jni_env, "FramePop");
+}
+
+void JNICALL
+GarbageCollectionFinish(jvmtiEnv *jvmti_env) {
+
+    display(1, "#### JVMTIagent: GarbageCollectionFinish occurred ####\n");
+
+    getVerdict(NULL, "GarbageCollectionFinish");
+}
+
+void JNICALL
+GarbageCollectionStart(jvmtiEnv *jvmti_env) {
+
+    display(1, "#### JVMTIagent: GarbageCollectionStart occurred ####\n");
+
+    getVerdict(NULL, "GarbageCollectionStart");
+}
+
+void JNICALL
+MonitorContendedEnter(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thr,
+        jobject obj) {
+
+    display(1, "#### JVMTIagent: MonitorContendedEnter occurred ####\n");
+
+    getVerdict(jni_env, "MonitorContendedEnter");
+}
+
+void JNICALL
+MonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thr,
+        jobject obj) {
+
+    display(1, "#### JVMTIagent: MonitorContendedEntered occurred ####\n");
+
+    getVerdict(jni_env, "MonitorContendedEntered");
+}
+
+void JNICALL
+MonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thr, jobject obj,
+        jlong tout) {
+
+    display(1, "#### JVMTIagent: MonitorWait occurred ####\n");
+
+    getVerdict(jni_env, "MonitorWait");
+}
+
+void JNICALL
+MonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env,
+        jthread thr, jobject obj, jboolean timed_out) {
+
+    display(1, "#### JVMTIagent: MonitorWaited occurred ####\n");
+
+    getVerdict(jni_env, "MonitorWaited");
+}
+
+void JNICALL
+NativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
+        jmethodID method, void *addr, void **new_addr) {
+
+    display(1, "#### JVMTIagent: NativeMethodBind occurred ####\n");
+
+    getVerdict(jni_env, "NativeMethodBind");
+}
+
+void JNICALL
+ObjectFree(jvmtiEnv *jvmti_env, jlong tag) {
+
+    display(1, "#### JVMTIagent: ObjectFree occurred ####\n");
+
+    getVerdict(NULL, "ObjectFree");
+}
+
+void JNICALL
+ThreadEnd(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thread) {
+
+    display(1, "#### JVMTIagent: ThreadEnd occurred ####\n");
+
+    getVerdict(jni_env, "ThreadEnd");
+}
+
+void JNICALL
+ThreadStart(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thread) {
+
+    display(1, "#### JVMTIagent: ThreadStart occurred ####\n");
+
+    getVerdict(jni_env, "ThreadStart");
+}
+
+void JNICALL
+VMDeath(jvmtiEnv *jvmti_env, JNIEnv *jni_env) {
+    vm_death_occured = TRUE;
+
+    display(0, "#### JVMTIagent: VMDeath occurred ####\n");
+
+    if (hotswap != HOTSWAP_OFF) {
+        deallocClsInfo(jni_env);
+        display(0, "#### JVMTIagent: allocated memory was successfully freed ####\n");
+    }
+}
+
+void JNICALL
+VMInit(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thr) {
+
+    display(0, "#### JVMTIagent: VMInit occurred ####\n");
+
+    getVerdict(jni_env, "VMInit");
+}
+
+void JNICALL
+VMStart(jvmtiEnv *jvmti_env, JNIEnv* jni_env) {
+
+    display(0, "#### JVMTIagent: VMStart occurred ####\n");
+
+    getVerdict(jni_env, "VMStart");
+}
+
+JNIEXPORT void JNICALL
+VMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
+        jobject object, jclass object_klass, jlong size) {
+
+    display(1, "#### JVMTIagent: VMObjectAlloc occurred ####\n");
+
+    getVerdict(jni_env, "VMObjectAlloc");
+}
+
+void JNICALL
+SingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
+        jmethodID method, jlocation location) {
+    jclass decl_clazz;
+
+    display((hotswap == HOTSWAP_EVERY_SINGLE_STEP)?0:1,
+        "#### JVMTIagent: SingleStep occurred ####\n");
+
+    getVerdict(jni_env, "SingleStep");
+
+    if (hotswap == HOTSWAP_EVERY_SINGLE_STEP) {
+        if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass,
+                jvmti_env, method, &decl_clazz)))
+            NSK_CPP_STUB2(FatalError, jni_env,
+                "JVMTIagent: failed to get method declaring class\n");
+
+        if (findAndHotSwap(jni_env, decl_clazz) != 0)
+            NSK_CPP_STUB2(FatalError, jni_env,
+                "JVMTIagent: failed to hotswap class\n");
+    }
+}
+
+void JNICALL
+MethodEntry(jvmtiEnv *jvmti_env, JNIEnv *jni_env,
+        jthread thr, jmethodID method) {
+    jclass decl_clazz;
+
+    display((hotswap == HOTSWAP_EVERY_METHOD_ENTRY ||
+            hotswap == HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS)?0:1,
+        "#### JVMTIagent: MethodEntry occurred ####\n");
+
+    getVerdict(jni_env, "MethodEntry");
+
+    if (hotswap == HOTSWAP_EVERY_METHOD_ENTRY ||
+            hotswap == HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS) {
+        if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass,
+                jvmti_env, method, &decl_clazz)))
+            NSK_CPP_STUB2(FatalError, jni_env,
+                "JVMTIagent: failed to get method declaring class\n");
+
+        if (findAndHotSwap(jni_env, decl_clazz) != 0)
+            NSK_CPP_STUB2(FatalError, jni_env,
+                "JVMTIagent: failed to hotswap class\n");
+    }
+}
+
+void JNICALL
+MethodExit(jvmtiEnv *jvmti_env, JNIEnv *jni_env,
+        jthread thr, jmethodID method,
+        jboolean was_poped_by_exc, jvalue return_value) {
+
+    display(1, "#### JVMTIagent: MethodExit occurred ####\n");
+
+    getVerdict(jni_env, "MethodExit");
+}
+
+void JNICALL
+ExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv *jni_env, jthread thr,
+        jmethodID method, jlocation location, jobject exception) {
+    jclass decl_clazz;
+
+    display((hotswap == HOTSWAP_EVERY_EXCEPTION ||
+            hotswap == HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS)?0:1,
+        "#### JVMTIagent: ExceptionCatch occurred ####\n");
+
+    getVerdict(jni_env, "ExceptionCatch");
+
+    if (hotswap == HOTSWAP_EVERY_EXCEPTION ||
+            hotswap == HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS) {
+        if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetMethodDeclaringClass,
+                jvmti_env, method, &decl_clazz)))
+            NSK_CPP_STUB2(FatalError, jni_env,
+                "JVMTIagent: failed to get method declaring class\n");
+
+        if (findAndHotSwap(jni_env, decl_clazz) != 0)
+            NSK_CPP_STUB2(FatalError, jni_env,
+                "JVMTIagent: failed to hotswap class\n");
+    }
+}
+/************************/
+
+static void lock(JNIEnv *jni_env) {
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter,
+            jvmti, eventLock)))
+        NSK_CPP_STUB2(FatalError, jni_env,
+            "JVMTIagent: failed to enter a raw monitor\n");
+}
+
+static void unlock(JNIEnv *jni_env) {
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit,
+            jvmti, eventLock)))
+        NSK_CPP_STUB2(FatalError, jni_env,
+            "JVMTIagent: failed to exit a raw monitor\n");
+}
+
+JNIEXPORT jint JNICALL
+Java_nsk_share_RASagent_setHotSwapMode(JNIEnv *jni_env, jclass cls,
+        jboolean vrb, jint level, jstring shortName) {
+    jvmtiCapabilities capabil;
+    jmethodID mid = NULL;
+
+    if (jvmti == NULL) {
+        printf("ERROR(%s,%d): JVMTIagent was not properly loaded: JVMTI env = NULL\n",
+               __FILE__, __LINE__);
+        return 1;
+    }
+
+    /* get supported JVMTI capabilities */
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetCapabilities,
+            jvmti, &capabil)))
+        NSK_CPP_STUB2(FatalError, jni_env,
+            "JVMTIagent: failed to get capabilities\n");
+    if (capabil.can_redefine_classes != 1) { /* ???????????? */
+        printf("ERROR: JVMTIagent: Class File Redefinition (HotSwap) is not implemented in this VM\n");
+        return 1;
+    }
+
+    if (vrb == JNI_TRUE && debug_mode == 0)
+        debug_mode = 1;
+
+    hotswap = level;
+    switch (hotswap) {
+        case HOTSWAP_OFF:
+            display(0, "#### JVMTIagent: hotswap mode off ####\n");
+            return 0;
+        case HOTSWAP_EVERY_METHOD_ENTRY:
+            stress_lev = 2;
+            display(0, "#### JVMTIagent: hotswapping class in every method entry event enabled ####\n\
+<JVMTIagent>\tHotSwap stress level: %d\n",
+                stress_lev);
+            break;
+        case HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS:
+            stress_lev = 2;
+            display(0, "#### JVMTIagent: hotswapping class in every method entry event for every class enabled ####\n\
+<JVMTIagent>\tHotSwap stress level: %d\n",
+                stress_lev);
+            break;
+        case HOTSWAP_EVERY_SINGLE_STEP:
+            stress_lev = 3;
+            display(0, "#### JVMTIagent: hotswapping class in every single step event enabled ####\n\
+<JVMTIagent>\tHotSwap stress level: %d\n",
+                stress_lev);
+            break;
+        case HOTSWAP_EVERY_EXCEPTION:
+            stress_lev = 4;
+            display(0, "#### JVMTIagent: hotswapping class in every exception event enabled ####\n\
+<JVMTIagent>\tHotSwap stress level: %d\n",
+                stress_lev);
+            break;
+        case HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS:
+            stress_lev = 40;
+            display(0, "#### JVMTIagent: hotswapping class in every exception event for every class enabled ####\n\
+<JVMTIagent>\tHotSwap stress level: %d\n",
+                stress_lev);
+            break;
+        default:
+            printf("ERROR(%s,%d): JVMTIagent: unknown value of HotSwap stress level: \"%d\"\n",
+                __FILE__,__LINE__,hotswap);
+            return 1;
+    }
+
+    if (!NSK_JNI_VERIFY(jni_env, (shortTestName = NSK_CPP_STUB3(GetStringUTFChars,
+            jni_env, shortName, NULL)) != NULL)) {
+        printf("ERROR: JVMTIagent: unable to get UTF-8 characters of the string\n");
+        return 1;
+    }
+    display(0, "#### JVMTIagent: short name of current test is \"%s\"\n",
+        shortTestName);
+
+    if (!NSK_JNI_VERIFY(jni_env, (rasCls = NSK_CPP_STUB2(NewGlobalRef,
+            jni_env, cls)) != NULL)) {
+        printf("ERROR JVMTIagent: unable to create a new global reference of the class \"RASagent\"\n");
+        return 1;
+    }
+
+    if (addStressEvents() != 0) {
+        printf("ERROR(%s,%d): JVMTIagent terminated abnormally! ####\n",
+            __FILE__,__LINE__);
+        return 1;
+    }
+
+    return 0;
+}
+
+static jint allocClsInfo(JNIEnv *jni_env, char *cls_sig, jclass clazz) {
+    class_info *_clsInfo = NULL;
+    jmethodID mid = NULL;
+    jbyteArray classBytes;
+    jboolean isCopy;
+
+    if ((_clsInfo = (class_info*)
+            malloc(sizeof(class_info))) == NULL)
+        NSK_CPP_STUB2(FatalError, jni_env,
+            "JVMTIagent: cannot allocate memory for class_info\n");
+
+    /* fill the structure class_info */
+    _clsInfo->clazzsig = cls_sig;
+
+    if (!NSK_JNI_VERIFY(jni_env, ((*_clsInfo).cls = NSK_CPP_STUB2(NewGlobalRef,
+            jni_env, clazz)) != NULL)) {
+        printf("ERROR: JVMTIagent: unable to create a new global reference of class \"%s\"\n",
+            _clsInfo->clazzsig);
+        free(_clsInfo);
+        deallocClsInfo(jni_env);
+        NSK_CPP_STUB2(FatalError, jni_env,
+            "JVMTIagent: unable to create a new global reference of class\n");
+    }
+
+    if (!NSK_JNI_VERIFY(jni_env, (mid =
+        NSK_CPP_STUB4(GetStaticMethodID, jni_env, rasCls,
+            "loadFromClassFile", "(Ljava/lang/String;)[B")) != NULL))
+        NSK_CPP_STUB2(FatalError, jni_env,
+            "JVMTIagent: unable to get ID of the method \"loadFromClassFile\"\n");
+
+    classBytes = (jbyteArray) NSK_CPP_STUB4(CallStaticObjectMethod,
+        jni_env, rasCls, mid, NSK_CPP_STUB2(NewStringUTF, jni_env, cls_sig));
+
+    clearJavaException(jni_env);
+
+    (*_clsInfo).bCount = NSK_CPP_STUB2(GetArrayLength, jni_env, classBytes);
+
+    (*_clsInfo).clsBytes =
+        NSK_CPP_STUB3(GetByteArrayElements, jni_env, classBytes, &isCopy);
+
+    _clsInfo->next = NULL;
+
+    if (clsInfo != NULL) {
+        clsInfo->next = (struct class_info*) _clsInfo;
+    }
+    else {
+        clsInfoFst = _clsInfo;
+    }
+    clsInfo = _clsInfo;
+
+    return (*_clsInfo).bCount;
+}
+
+static void deallocClsInfo(JNIEnv *jni_env) {
+    class_info *clsInfoCurr = clsInfoFst;
+
+    NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni_env, rasCls));
+
+    while(clsInfoCurr != NULL) {
+        class_info *_clsInfo = clsInfoCurr;
+
+        if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
+                jvmti, (unsigned char*) clsInfoCurr->clazzsig)))
+            NSK_CPP_STUB2(FatalError, jni_env,
+                "JVMTIagent: failed to deallocate memory for clazzsig\n");
+
+        NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni_env, clsInfoCurr->cls));
+
+        clsInfoCurr = (class_info*) clsInfoCurr->next;
+
+        free(_clsInfo);
+    }
+    /* fix for 4756585: indicate that stucture class_info is empty now */
+    clsInfoFst = NULL;
+}
+
+static int findAndHotSwap(JNIEnv *jni_env, jclass clazz) {
+    int ret_code = 0;
+    char *clazzsig = NULL;
+    class_info *clsInfoCurr = clsInfoFst;
+
+    display(1, "\n#### JVMTIagent: findAndHotSwap: obtaining class signature of class to be hotswap ...\n");
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature,
+            jvmti, clazz, &clazzsig, /*&generic*/NULL)))
+        NSK_CPP_STUB2(FatalError, jni_env,
+            "JVMTIagent: findAndHotSwap: failed to get class signature\n");
+    else {
+        display(1, "#### JVMTIagent: findAndHotSwap: ... class signature obtained: \"%s\"\n",
+            clazzsig);
+
+        /* enter into a raw monitor for exclusive work with redefined class */
+        lock(jni_env);
+        display(0, "#### JVMTIagent: findAndHotSwap: >>>>>>>> entered the raw monitor \"eventLock\" ####\n");
+
+        while(clsInfoCurr != NULL) {
+            if (hotswap == HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS ||
+                    hotswap == HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS) {
+                display(1, "\n#### JVMTIagent: findAndHotSwap: going to hotswap tested class \"%s\" during execution of class \"%s\" ...\n",
+                    clsInfoCurr->clazzsig, clazzsig);
+                if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
+                        jvmti, (unsigned char*) clazzsig)))
+                    NSK_CPP_STUB2(FatalError, jni_env,
+                        "JVMTIagent: findAndHotSwap: failed to deallocate memory for clazzsig\n");
+
+                if (doHotSwap(jni_env, clsInfoCurr->cls,
+                        clsInfoCurr->bCount, clsInfoCurr->clsBytes) != 0) {
+                    ret_code = 1;
+                    break;
+                }
+            }
+            else {
+                if (strcmp(clazzsig, clsInfoCurr->clazzsig) == 0) {
+                    display(0, "\n#### JVMTIagent: findAndHotSwap: tested class found \"%s\" ...\n",
+                        clazzsig);
+
+                    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
+                            jvmti, (unsigned char*) clazzsig)))
+                        NSK_CPP_STUB2(FatalError, jni_env,
+                            "JVMTIagent: findAndHotSwap: failed to deallocate memory for clazzsig\n");
+
+                    display(0, "\n#### JVMTIagent: findAndHotSwap: going to hotswap tested class \"%s\" ...\n",
+                        clsInfoCurr->clazzsig);
+                    if (doHotSwap(jni_env, clsInfoCurr->cls,
+                            clsInfoCurr->bCount, clsInfoCurr->clsBytes) != 0) {
+                        ret_code = 1;
+                        break;
+                    }
+                }
+            }
+
+            clsInfoCurr = (class_info*) clsInfoCurr->next;
+        }
+
+        /* exit raw monitor */
+        unlock(jni_env);
+        display(0, "#### JVMTIagent: findAndHotSwap: <<<<<<<< exited from the raw monitor \"eventLock\" ####\n\n");
+    }
+
+    return ret_code;
+}
+
+static int doHotSwap(JNIEnv *jni_env, jclass redefCls, jint bCount,
+        jbyte *classBytes) {
+    jvmtiClassDefinition classDef;
+
+    /* fill the structure jvmtiClassDefinition */
+    classDef.klass = redefCls;
+    classDef.class_byte_count = bCount;
+    classDef.class_bytes = (unsigned char*) classBytes;
+
+    display(0, "#### JVMTIagent: >>>>>>>> Invoke RedefineClasses():\n\
+<JVMTIagent>\tnew class byte count=%d\n",
+        classDef.class_byte_count);
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(RedefineClasses,
+            jvmti, 1, &classDef)))
+        return 1;
+
+    display(0, "#### JVMTIagent: <<<<<<<< RedefineClasses() is successfully done ####\n");
+
+    return 0;
+}
+
+static int addStressEvents() {
+    static int stepEventSet = JNI_FALSE;
+    static int methodsEventSet = JNI_FALSE;
+    static int excCatchEventSet = JNI_FALSE;
+
+    if (stress_lev >= 3) {
+        /* SingleStep events */
+        if (stepEventSet == JNI_FALSE) { /* don't set the event twice */
+            display(0, "#### JVMTIagent: setting SingleStep events ...\n");
+
+            callbacks.SingleStep = &SingleStep;
+
+            if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+                    jvmti, JVMTI_ENABLE, JVMTI_EVENT_SINGLE_STEP, NULL)))
+                return JNI_ERR;
+
+            stepEventSet = JNI_TRUE;
+
+            display(0, "#### JVMTIagent: ... setting SingleStep events done\n");
+        }
+    }
+
+    if (stress_lev >= 2) {
+        /* MethodEntry/Exit events */
+        if (methodsEventSet == JNI_FALSE) { /* don't set the event twice */
+            display(0, "#### JVMTIagent: setting MethodEntry events ...\n");
+
+            callbacks.MethodEntry = &MethodEntry;
+
+            if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+                    jvmti, JVMTI_ENABLE, JVMTI_EVENT_METHOD_ENTRY, NULL)))
+                return JNI_ERR;
+
+            display(0, "#### JVMTIagent: ... setting MethodEntry events done\n");
+
+            /* MethodExit events */
+            display(0, "#### JVMTIagent: setting MethodExit events ...\n");
+
+            callbacks.MethodExit = &MethodExit;
+
+            if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+                    jvmti, JVMTI_ENABLE, JVMTI_EVENT_METHOD_EXIT, NULL)))
+                return JNI_ERR;
+
+            display(0, "#### JVMTIagent: ... setting MethodExit events done\n");
+
+            methodsEventSet = JNI_TRUE;
+        }
+    }
+
+    if (stress_lev >= 1) {
+        /* ExceptionCatch events */
+        if (excCatchEventSet == JNI_FALSE) { /* don't set the event twice */
+            display(0, "#### JVMTIagent: setting ExceptionCatch events ...\n");
+
+            callbacks.ExceptionCatch = &ExceptionCatch;
+
+            if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+                    jvmti, JVMTI_ENABLE, JVMTI_EVENT_EXCEPTION_CATCH, NULL)))
+                return JNI_ERR;
+
+            excCatchEventSet = JNI_TRUE;
+
+            display(0, "#### JVMTIagent: ... setting ExceptionCatch events done\n");
+        }
+    }
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks,
+            jvmti, &callbacks, sizeof(callbacks))))
+        return JNI_ERR;
+    else
+        return 0;
+}
+
+static int enableEventsCaps() {
+    jvmtiCapabilities caps;
+
+    memset(&caps, 0, sizeof(jvmtiCapabilities));
+
+    /* add all capabilities */
+    caps.can_redefine_classes = 1;
+    caps.can_generate_breakpoint_events = 1;
+    caps.can_generate_all_class_hook_events = 1;
+    caps.can_generate_single_step_events = 1;
+    caps.can_generate_method_entry_events = 1;
+    caps.can_generate_method_exit_events = 1;
+    caps.can_generate_exception_events = 1;
+    caps.can_generate_compiled_method_load_events = 1;
+    caps.can_generate_field_access_events = 1;
+    caps.can_generate_field_modification_events = 1;
+    caps.can_generate_frame_pop_events = 1;
+    caps.can_generate_garbage_collection_events = 1;
+    caps.can_generate_monitor_events = 1;
+    caps.can_generate_native_method_bind_events = 1;
+    caps.can_generate_object_free_events = 1;
+    caps.can_generate_vm_object_alloc_events = 1;
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities,
+            jvmti, &caps)))
+        return JNI_ERR;
+
+    /* Breakpoint events */
+    display(0, "#### JVMTIagent: setting Breakpoint events ...\n");
+
+    callbacks.Breakpoint = &Breakpoint;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_BREAKPOINT, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting Breakpoint events done\n");
+
+    /* ClassFileLoadHook events */
+    display(0, "#### JVMTIagent: setting ClassFileLoadHook events ...\n");
+
+    callbacks.ClassFileLoadHook = &ClassFileLoadHook;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting ClassFileLoadHook events done\n");
+
+    /* ClassLoad events */
+    display(0, "#### JVMTIagent: setting ClassLoad events ...\n");
+
+    callbacks.ClassLoad = &ClassLoad;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_LOAD, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting ClassLoad events done\n");
+
+    /* ClassPrepare events */
+    display(0, "#### JVMTIagent: setting ClassPrepare events ...\n");
+
+    callbacks.ClassPrepare = &ClassPrepare;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_PREPARE, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting ClassPrepare events done\n");
+
+    /* CompiledMethodLoad events */
+    display(0, "#### JVMTIagent: setting CompiledMethodLoad events ...\n");
+
+    callbacks.CompiledMethodLoad = &CompiledMethodLoad;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting CompiledMethodLoad events done\n");
+
+    /* CompiledMethodUnload events */
+    display(0, "#### JVMTIagent: setting CompiledMethodUnload events ...\n");
+
+    callbacks.CompiledMethodUnload = &CompiledMethodUnload;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_COMPILED_METHOD_UNLOAD, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting CompiledMethodUnload events done\n");
+
+    /* DataDumpRequest events */
+    display(0, "#### JVMTIagent: setting DataDumpRequest events ...\n");
+
+    callbacks.DataDumpRequest = &DataDumpRequest;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_DATA_DUMP_REQUEST, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting DataDumpRequest events done\n");
+
+    /* DynamicCodeGenerated events */
+    display(0, "#### JVMTIagent: setting DynamicCodeGenerated events ...\n");
+
+    callbacks.DynamicCodeGenerated = &DynamicCodeGenerated;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_DYNAMIC_CODE_GENERATED, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting DynamicCodeGenerated events done\n");
+
+    /* Exception events */
+    display(0, "#### JVMTIagent: setting Exception events ...\n");
+
+    callbacks.Exception = &Exception;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_EXCEPTION, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting Exception events done\n");
+
+    /* FieldAccess events */
+    display(0, "#### JVMTIagent: setting FieldAccess events ...\n");
+
+    callbacks.FieldAccess = &FieldAccess;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_FIELD_ACCESS, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting FieldAccess events done\n");
+
+    /* FieldModification events */
+    display(0, "#### JVMTIagent: setting FieldModification events ...\n");
+
+    callbacks.FieldModification = &FieldModification;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_FIELD_MODIFICATION, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting FieldModification events done\n");
+
+    /* FramePop events */
+    display(0, "#### JVMTIagent: setting FramePop events ...\n");
+
+    callbacks.FramePop = &FramePop;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_FRAME_POP, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting FramePop events done\n");
+
+    /* GarbageCollectionFinish events */
+    display(0, "#### JVMTIagent: setting GarbageCollectionFinish events ...\n");
+
+    callbacks.GarbageCollectionFinish = &GarbageCollectionFinish;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting GarbageCollectionFinish events done\n");
+
+    /* GarbageCollectionStart events */
+    display(0, "#### JVMTIagent: setting GarbageCollectionStart events ...\n");
+
+    callbacks.GarbageCollectionStart = &GarbageCollectionStart;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_GARBAGE_COLLECTION_START, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting GarbageCollectionStart events done\n");
+
+    /* MonitorContendedEnter events */
+    display(0, "#### JVMTIagent: setting MonitorContendedEnter events ...\n");
+
+    callbacks.MonitorContendedEnter = &MonitorContendedEnter;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_MONITOR_CONTENDED_ENTER, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting MonitorContendedEnter events done\n");
+
+    /* MonitorContendedEntered events */
+    display(0, "#### JVMTIagent: setting MonitorContendedEntered events ...\n");
+
+    callbacks.MonitorContendedEntered = &MonitorContendedEntered;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting MonitorContendedEntered events done\n");
+
+    /* MonitorWait events */
+    display(0, "#### JVMTIagent: setting MonitorWait events ...\n");
+
+    callbacks.MonitorWait = &MonitorWait;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_MONITOR_WAIT, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting MonitorWait events done\n");
+
+    /* MonitorWaited events */
+    display(0, "#### JVMTIagent: setting MonitorWaited events ...\n");
+
+    callbacks.MonitorWaited = &MonitorWaited;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_MONITOR_WAITED, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting MonitorWaited events done\n");
+
+    /* NativeMethodBind events */
+    display(0, "#### JVMTIagent: setting NativeMethodBind events ...\n");
+
+    callbacks.NativeMethodBind = &NativeMethodBind;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_NATIVE_METHOD_BIND, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting NativeMethodBind events done\n");
+
+    /* ObjectFree events */
+    display(0, "#### JVMTIagent: setting ObjectFree events ...\n");
+
+    callbacks.ObjectFree = &ObjectFree;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_OBJECT_FREE, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting ObjectFree events done\n");
+
+    /* ThreadEnd events */
+    display(0, "#### JVMTIagent: setting ThreadEnd events ...\n");
+
+    callbacks.ThreadEnd = &ThreadEnd;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_THREAD_END, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting ThreadEnd events done\n");
+
+    /* ThreadStart events */
+    display(0, "#### JVMTIagent: setting ThreadStart events ...\n");
+
+    callbacks.ThreadStart = &ThreadStart;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_THREAD_START, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting ThreadStart events done\n");
+
+    /* VMDeath events */
+    display(0, "#### JVMTIagent: setting VMDeath events ...\n");
+
+    callbacks.VMDeath = &VMDeath;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting VMDeath events done\n");
+
+    /* VMInit events */
+    display(0, "#### JVMTIagent: setting VMInit events ...\n");
+
+    callbacks.VMInit = &VMInit;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting VMInit events done\n");
+
+    /* VMStart events */
+    display(0, "#### JVMTIagent: setting VMStart events ...\n");
+
+    callbacks.VMStart = &VMStart;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_START, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting VMStart events done\n");
+
+    /* VMObjectAlloc events */
+    display(0, "#### JVMTIagent: setting VMObjectAlloc events ...\n");
+
+    callbacks.VMObjectAlloc = &VMObjectAlloc;
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
+            jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_OBJECT_ALLOC, NULL)))
+        return JNI_ERR;
+    display(0, "#### JVMTIagent: ... setting VMObjectAlloc events done\n");
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks,
+            jvmti, &callbacks, sizeof(callbacks))))
+        return JNI_ERR;
+
+    return 0;
+}
+
+static void clearJavaException(JNIEnv* jni_env) {
+    if (NSK_CPP_STUB1(ExceptionOccurred, jni_env)) {
+
+        NSK_CPP_STUB1(ExceptionDescribe, jni_env);
+        NSK_CPP_STUB1(ExceptionClear, jni_env);
+
+        NSK_CPP_STUB2(FatalError, jni_env,
+            "JVMTIagent: exception occurred in java code, aborting\n");
+    }
+}
+
+static int get_tok(char **src, char *buf, int buflen, char sep) {
+    int i;
+    char *p = *src;
+    for (i = 0; i < buflen; i++) {
+        if (p[i] == 0 || p[i] == sep) {
+            buf[i] = 0;
+            if (p[i] == sep) {
+                i++;
+            }
+            *src += i;
+            return i;
+        }
+        buf[i] = p[i];
+    }
+    /* overflow */
+    return 0;
+}
+
+static void doSetup(char *str) {
+    if (str == 0)
+        str = "";
+
+    if ((strcmp(str, "help")) == 0) {
+        printf("#### JVMTIagent usage: -agentlib:JVMTIagent[=[help]|[=[verbose]|[verbose2],[stress0|stress1|stress2|stress3]]]\n");
+        printf("####      where: help\tprint this message\n");
+        printf("####             verbose\tturn verbose mode on\n");
+        printf("####             verbose2\tturn extended verbose mode on (including reporting JVMTI events)\n");
+        printf("####             stress0, or empty value\tturn stress level 0 on (default mode):\n");
+        printf("####                   enable event generation except ExceptionCatch, MethodEntry/Exit, SingleStep\n");
+        printf("####             stress1\tturn stress level 1 on:\n");
+        printf("####                   enable generation of ExceptionCatch events\n");
+        printf("####             stress2\tturn stress level 2 on:\n");
+        printf("####                   enable generation of ExceptionCatch,\n");
+        printf("####                                        MethodEntry/Exit events\n");
+        printf("####             stress3\tturn stress level 3 on:\n");
+        printf("####                   enable generation of ExceptionCatch,\n");
+        printf("####                                        MethodEntry/Exit,\n");
+        printf("####                                        SingleStep events\n");
+        exit(1);
+    }
+
+    while (*str) {
+        char buf[1000];
+
+        if (!get_tok(&str, buf, sizeof(buf), ',')) {
+            printf("ERROR: JVMTIagent: bad option: \"%s\"!\n", str);
+            exit(1);
+        }
+        if ((strcmp(buf, "verbose")) == 0) {
+            printf("#### JVMTIagent: turned verbose mode on ####\n");
+            debug_mode = 1;
+        }
+        if ((strcmp(buf, "verbose2")) == 0) {
+            printf("#### JVMTIagent: turned extended verbose mode on ####\n");
+            debug_mode = 2;
+        }
+        if ((strcmp(buf, "stress0")) == 0) {
+            if (debug_mode > 0)
+                printf("#### JVMTIagent: turned stress level 0 on ####\n");
+            stress_lev = 0;
+        }
+        if ((strcmp(buf, "stress1")) == 0) {
+            if (debug_mode > 0)
+                printf("#### JVMTIagent: turned stress level 1 on ####\n");
+            stress_lev = 1;
+        }
+        if ((strcmp(buf, "stress2")) == 0) {
+            if (debug_mode > 0)
+                printf("#### JVMTIagent: turned stress level 2 on ####\n");
+            stress_lev = 2;
+        }
+        if ((strcmp(buf, "stress3")) == 0) {
+            if (debug_mode > 0)
+                printf("#### JVMTIagent: turned stress level 3 on ####\n");
+            stress_lev = 3;
+        }
+    }
+}
+
+static void getVerdict(JNIEnv *jni_env, const char *evnt) {
+    char error_msg[80];
+
+    if (vm_death_occured == TRUE) {
+        sprintf(error_msg, "JVMTIagent: getVerdict: %s event occured after VMDeath",
+            evnt);
+
+        if (jni_env==NULL) { /* some event callbacks have no pointer to jni */
+            printf("ERROR: %s\n", error_msg);
+            exit(97);
+        }
+        else
+            NSK_CPP_STUB2(FatalError, jni_env, error_msg);
+    }
+}
+
+static void display(int level, const char format[], ...) {
+    va_list ar;
+
+    if (debug_mode > level) {
+        va_start(ar, format);
+        vprintf(format, ar);
+        va_end(ar);
+    }
+}
+
+/* agent procedure */
+static void JNICALL
+agentProc(jvmtiEnv* jvmti_env, JNIEnv* jni_env, void* arg) {
+}
+
+JNIEXPORT jint JNICALL
+Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) {
+    /* create JVMTI environment */
+    if (!NSK_VERIFY((jvmti =
+            nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
+        return JNI_ERR;
+
+    doSetup(options);
+
+    if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(CreateRawMonitor,
+            jvmti, "_event_lock", &eventLock)))
+        return JNI_ERR;
+
+    if (enableEventsCaps() == 0 && addStressEvents() == 0) {
+        display(0, "#### JVMTIagent: all events were successfully enabled and capabilities/events callbacks set ####\n\n");
+    } else {
+        printf("ERROR(%s,%d): JVMTIagent terminated abnormally! ####\n",
+            __FILE__,__LINE__);
+        return JNI_ERR;
+    }
+
+    /* register agent proc and arg */
+    if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
+        return JNI_ERR;
+
+    return JNI_OK;
+}
+
+#ifdef __cplusplus
+}
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/LocalProcess.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 2002, 2018, 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.
+ */
+
+package nsk.share;
+
+import nsk.share.*;
+
+import java.io.*;
+
+/**
+ * Wrapper for local process.
+ * <p>
+ * This class provides abilities to launch such process,
+ * redirect standard output streams, wait for process terminates
+ * or kill the process, and so on.
+ * <p>
+ * This object is finalized with <code>nsk.share.Finalizer</code>.
+ *
+ * @see nsk.share.FinalizableObject
+ * @see nsk.share.Finalizer
+ */
+
+public class LocalProcess extends FinalizableObject {
+
+    public final static int PROCESS_IS_ALIVE = 222;
+
+    private Process process;
+
+    protected Process getProcess() {
+        return process;
+    }
+
+    public void launch (String[] args) throws IOException {
+        System.out.println("Launching process by array of args: ");
+        for (int mm=0; mm < args.length; mm++) {
+            System.out.println("    args[" + Integer.toString(mm) + "]: >" +
+                               args[mm] + "<");
+
+        }
+
+        process = Runtime.getRuntime().exec(args);
+
+        Finalizer finalizer = new Finalizer(this);
+        finalizer.activate();
+    }
+
+    public void launch (String cmdLine) throws IOException {
+        System.out.println("Launching process by command line: " + cmdLine);
+
+        process = Runtime.getRuntime().exec(cmdLine);
+
+        Finalizer finalizer = new Finalizer(this);
+        finalizer.activate();
+    }
+
+    /** Return exit status. */
+    public int getStatus () {
+        return process.exitValue();
+    }
+
+    /** Check whether the process has been terminated. */
+    public boolean terminated() {
+        try {
+            int value = process.exitValue();
+            return true;
+        } catch (IllegalThreadStateException e) {
+            return false;
+        }
+    }
+
+    /** Wait until the process shutdown or crash. */
+    public int waitFor () throws InterruptedException {
+        return process.waitFor();
+    }
+
+    /**
+     * Wait until the process shutdown or crash for given timeout in milliseconds.
+     * Returns <code>LocalProcess.PROCESS_IS_ALIVE</code> if process is not terminated
+     * after timeout.
+     */
+
+    public int waitFor (long timeMillisec) throws InterruptedException {
+        final Object waitObject = new Object();
+
+        class Watcher extends Thread {
+            int exitCode = LocalProcess.PROCESS_IS_ALIVE;
+            Process process;
+
+            Watcher (Process process) {
+               this.process = process;
+            }
+
+            public void run () {
+                try {
+                    synchronized (this) {
+                       exitCode = process.waitFor();
+                    }
+                } catch (InterruptedException ie) {
+                }
+                synchronized (waitObject) {
+                    waitObject.notifyAll();
+                }
+            }
+
+            synchronized public int getExitCode() {
+                return exitCode;
+            }
+        }
+
+        Watcher watcher;
+        // yield control to watcher for timeMillisec time.
+        synchronized (waitObject) {
+            watcher = new Watcher(process);
+            watcher.start();
+
+            waitObject.wait(timeMillisec);
+        }
+
+        if (watcher.isAlive()) {
+            watcher.interrupt();
+        }
+
+        return watcher.getExitCode();
+    }
+
+    // --------------------------------------------------- //
+
+    /** Get a pipe to write to the process' stdin stream. */
+    public OutputStream getStdin () {
+        return process.getOutputStream();
+    }
+
+    /** Get a pipe to read the process' stdout stream. */
+    public InputStream getStdout () {
+        return process.getInputStream();
+    }
+
+    /** Get a pipe to read the process stderr stream. */
+    public InputStream getStderr () {
+        return process.getErrorStream();
+    }
+
+    /** Kill the process. */
+    protected void kill() {
+        process.destroy();
+    }
+
+    /**
+     * Finalize mirror by invoking <code>close()</code>.
+     *
+     * @throws Throwable if any throwable exception is thrown during finalization
+     */
+    protected void finalize() throws Throwable {
+        kill();
+        super.finalize();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/Log.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,736 @@
+/*
+ * Copyright (c) 2001, 2018, 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.
+ */
+
+package nsk.share;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Vector;
+
+import nsk.share.test.LazyFormatString;
+
+/**
+ * This class helps to print test-execution trace messages
+ * and filter them when execution mode is not verbose.
+ * <p>
+ * Verbose mode if defined by providing <i>-verbose</i> command line
+ * option, handled by <code>ArgumentParser</code>. Use <code>verbose()</code>
+ * method to determine which mode is used.
+ * <p>
+ * <code>Log</code> provides with two main methods to print messages:
+ * <ul>
+ *   <li> <code>complain(String)</code> - to print error message
+ *   <li> <code>display(String)</code> - to print additional log message
+ * </ul>
+ * No other way to print messages to the log stream should be used.
+ * <p>
+ * Error messages appeares in log stream in all modes. Additional log massages,
+ * printed with <code>display()</code> method will be filtered out, if log mode
+ * is not verbose. In verbose log made messages of both types are printed.
+ * Additionally, in verbose mode a summary of all occured errors will be printed
+ * at the program exit, by automatically invoking method
+ * <code>printErrorsSummary()</code>.
+ * <p>
+ * To provide printing messages from different sources into one log
+ * with distinct prefixes use internal <code>Log.Logger</code> class.
+ *
+ * @see #verbose()
+ * @see #complain(String)
+ * @see #display(String)
+ * @see ArgumentParser
+ * @see Log.Logger
+ */
+public class Log extends FinalizableObject {
+    /**
+     * Report step-by-step activity to this stream.
+     *
+     * @deprecated  Tests should not use this field directly.
+     */
+    protected PrintStream out = null;
+
+    /**
+     * Is log-mode verbose?
+     * Default value is <code>false</code>.
+     */
+    private boolean verbose = false;
+
+    /**
+     * Should log messages prefixed with timestamps?
+     * Default value is <code>false</code>.
+     */
+    private boolean timestamp = false;
+
+    /**
+     * Names for trace levels
+     */
+    public static final class TraceLevel {
+        public static final int TRACE_NONE = 0;
+        public static final int TRACE_IMPORTANT = 1;
+        public static final int TRACE_NORMAL = 2;
+        public static final int TRACE_VERBOSE = 3;
+        public static final int TRACE_DEBUG = 4;
+
+        public static final int DEFAULT = TRACE_IMPORTANT;
+
+        public static final Map<String, Integer> NAME_TO_LEVEL_MAP = new HashMap<String, Integer>();
+        static {
+            NAME_TO_LEVEL_MAP.put("none", TRACE_NONE);
+            NAME_TO_LEVEL_MAP.put("important", TRACE_IMPORTANT);
+            NAME_TO_LEVEL_MAP.put("info", TRACE_NORMAL);
+            NAME_TO_LEVEL_MAP.put("verbose", TRACE_VERBOSE);
+            NAME_TO_LEVEL_MAP.put("debug", TRACE_DEBUG);
+            NAME_TO_LEVEL_MAP.put("default", DEFAULT);
+        }
+
+        public static int nameToLevel(String value) throws IllegalArgumentException {
+            Integer level = NAME_TO_LEVEL_MAP.get(value.toLowerCase());
+            if ( level == null )
+                throw new IllegalArgumentException("Wrong trace level: " + value);
+
+            return level;
+        }
+
+        public static String getLevelsString() {
+            StringBuffer result = new StringBuffer();
+            for ( String s : NAME_TO_LEVEL_MAP.keySet() ) {
+                result.append(s).append(", ");
+            }
+            return result.substring(0, result.length() - 3);
+        }
+    }
+
+    /**
+     * Threshold value for printing trace messages for debugging purpose.
+     * Default value is <code>0</code> a.k.a. <code>TraceLevel.INFO</code>;
+     */
+    private int traceLevel = TraceLevel.DEFAULT;
+
+    /**
+     * Is printing errors summary enabled? Default value is <code>true</code>;
+     */
+    private boolean errorsSummaryEnabled = true;
+
+    /**
+     * Is printing saved verbose messages on error enabled? Default value is <code>true</code>;
+     */
+    private boolean verboseOnErrorEnabled = true;
+
+    /**
+     * This <code>errosBuffer</code> will keep all messages printed via
+     * <code>complain()</code> method for final summary output.
+     * Ensure that buffer has enough room for messages to keep,
+     * to minimize probability or OutOfMemory error while keeping
+     * an error message in stress tests.
+     */
+    private Vector<String> errorsBuffer = new Vector<String>(1000);
+
+    /**
+     * Most tests in nsk do not log exceptions, they only log an error message.
+     * This makes failure analysis harder.
+     * To solve this we will automatically generate Exceptions for error logs.
+     * To not log too many Exceptions, we try to log each unique error only once.
+     * <code>loggedExceptions</code> contains all messages that have already been logged.
+     */
+    private Set<String> loggedExceptions = new HashSet<String>();
+
+    /**
+     * This <code>logBuffer</code> will keep all messages printed via
+     * <code>display()</code> method in non-verbose mode until
+     * swithching verbose mode on or invoking <code>complain()</code>.
+     * Ensure that buffer has enough room for messages to keep,
+     * to minimize probability or OutOfMemory error while keeping
+     * an error message in stress tests.
+     */
+    private Vector<String> logBuffer = new Vector<String>(1000);
+
+    /**
+     * Did I already warned if output stream is not assigned?
+     */
+    private boolean noOutWarned = false;
+
+    /////////////////////////////////////////////////////////////////
+
+    /**
+     * Create new Log's only with <code>Log(out)</code> or with
+     * <code>Log(out,argsHandler)</code> constructors.
+     *
+     * @deprecated  Extending test class with Log is obsolete.
+     */
+    protected Log() {
+        // install finalizer to print errors summary at exit
+        Finalizer finalizer = new Finalizer(this);
+        finalizer.activate();
+
+        // Don't log exceptions from this method. It would just add unnecessary logs.
+        loggedExceptions.add("nsk.share.jdi.SerialExecutionDebugger.executeTests");
+    }
+
+    /**
+     * Incarnate new Log for the given <code>stream</code> and
+     * for non-verbose mode.
+     */
+    public Log(PrintStream stream) {
+        this();
+        out = stream;
+    }
+
+    /**
+     * Incarnate new Log for the given <code>stream</code>; and
+     * either for verbose or for non-verbose mode accordingly to
+     * the given <code>verbose</code> key.
+     */
+    public Log(PrintStream stream, boolean verbose) {
+        this(stream);
+        this.verbose = verbose;
+    }
+
+    /**
+     * Incarnate new Log for the given <code>stream</code>; and
+     * either for verbose or for non-verbose mode accordingly to
+     * the given <code>argsHandler</code>.
+     */
+    public Log(PrintStream stream, ArgumentParser argsParser) {
+        this(stream, argsParser.verbose());
+        traceLevel = argsParser.getTraceLevel();
+        timestamp = argsParser.isTimestamp();
+    }
+
+    /////////////////////////////////////////////////////////////////
+
+    /**
+     * Return <i>true</i> if log mode is verbose.
+     */
+    public boolean verbose() {
+        return verbose;
+    }
+
+    /**
+     * Return <i>true</i> if printing errors summary at exit is enabled.
+     */
+    public boolean isErrorsSummaryEnabled() {
+        return errorsSummaryEnabled;
+    }
+
+    /**
+     * Enable or disable printing errors summary at exit.
+     */
+    public void enableErrorsSummary(boolean enable) {
+        errorsSummaryEnabled = enable;
+    }
+
+    /**
+     * Return <i>true</i> if printing saved verbose messages on error is enabled.
+     */
+    public boolean isVerboseOnErrorEnabled() {
+        return errorsSummaryEnabled;
+    }
+
+    /**
+     * Enable or disable printing saved verbose messages on error.
+     */
+    public void enableVerboseOnError(boolean enable) {
+        verboseOnErrorEnabled = enable;
+    }
+
+    /**
+     * Enable or disable verbose mode for printing messages.
+     */
+    public void enableVerbose(boolean enable) {
+        if (!verbose) {
+            flushLogBuffer();
+        }
+        verbose = enable;
+    }
+
+    public int getTraceLevel() {
+        return traceLevel;
+    }
+
+    /**
+     * Set threshold for printing trace messages.
+     * Warning: trace level changes may NOT be observed by other threads immediately.
+     */
+    public void setTraceLevel(int level) {
+        traceLevel = level;
+    }
+
+    /**
+     * Return output stream of this <code>Log</code> object.
+     */
+    public PrintStream getOutStream() {
+        return out;
+    }
+
+    /**
+     * Returns a string that contains prefix concatenated
+     * with Throwable.printStackTrace() output.
+     */
+    public static String printExceptionToString(Object prefix, Throwable exception) {
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        PrintWriter pw = new PrintWriter(bos);
+        pw.println(prefix);
+        exception.printStackTrace(pw);
+        pw.close();
+        return bos.toString();
+    }
+
+    /**
+     * Print <code>message</code> to the assigned output stream.
+     *
+     * @deprecated  Test ought to be quiet if log mode is non-verbose
+     *              and there is no errors found by the test. Methods
+     *              <code>display()</code> and <code>complain()</code>
+     *              are enough for testing purposes.
+     */
+    public synchronized void println(String message) {
+        doPrint(message);
+        if (!verbose() && isVerboseOnErrorEnabled()) {
+            keepLog(composeLine(message));
+        }
+    }
+
+    /**
+     * Print <code>message</code> to the assigned output stream,
+     * if log mode is <i>non</i>-verbose.
+     *
+     * @deprecated  Test ought to be quiet if log mode is non-verbose
+     *              and there is no errors found by the test. Methods
+     *              <code>display()</code> and <code>complain()</code>
+     *              are enough for testing purposes.
+     */
+    public synchronized void comment(String message) {
+        if (!verbose()) {
+            doPrint(message);
+        }
+    }
+
+    /**
+     * Print trace <code>message</code> to the assigned output stream,
+     * only if specified <code>level</code> is less or equal for the
+     * trace level specified in command line by <code>-trace.level</code>
+     * option.
+     */
+    public void trace(int level, Object message) {
+        if (level <= traceLevel) {
+            synchronized ( this ) {
+                doPrint("### TRACE " + level + ": " + message);
+            }
+        }
+    }
+    /**
+     * Print trace <code>message</code> and <code>exception</code> to
+     * the assigned output stream,
+     * only if specified <code>level</code> is less or equal for the
+     * trace level specified in command line by <code>-trace.level</code>
+     * option.
+     */
+    public void trace(int level, Object message, Throwable exception) {
+        if (level <= traceLevel) {
+            trace(level, printExceptionToString(message, exception));
+        }
+    }
+
+    /**
+     * Print <code>message</code> to the assigned output stream,
+     * if log mode is verbose. The <code>message</code> will be lost,
+     * if execution mode is non-verbose, and there is no error messages
+     * printed.
+     */
+    public synchronized void display(Object message) {
+        if (verbose()) {
+            doPrint(message.toString());
+        } else if (isVerboseOnErrorEnabled()) {
+            keepLog(composeLine(message.toString()));
+        } else {
+            // ignore
+        }
+    }
+
+    /**
+     * Print error <code>message</code> to the assigned output stream
+     * (or to stderr if output is not specified) and keep the message
+     * into <code>errorsBuffer</code>.
+     */
+    public synchronized void complain(Object message) {
+        if (!verbose() && isVerboseOnErrorEnabled()) {
+            PrintStream stream = findOutStream();
+            stream.println("#>  ");
+            stream.println("#>  WARNING: switching log to verbose mode,");
+            stream.println("#>      because error is complained");
+            stream.println("#>  ");
+            stream.flush();
+            enableVerbose(true);
+        }
+        String msgStr = message.toString();
+        printError(msgStr);
+        if (isErrorsSummaryEnabled()) {
+            keepError(msgStr);
+        }
+
+        logExceptionForFailureAnalysis(msgStr);
+    }
+
+    /**
+     * Print error <code>message</code> and <code>exception</code>
+     * to the assigned output stream
+     * (or to stderr if output is not specified) and keep the message
+     * into <code>errorsBuffer</code>.
+     */
+    public void complain(Object message, Throwable exception) {
+        if ( exception != null )
+            complain(printExceptionToString(message, exception));
+        else
+            complain(message);
+    }
+
+    /**
+     * Create an Exception and print the stack trace for an error msg.
+     * This makes it possible to detect a failure reason for this error.
+     */
+    private void logExceptionForFailureAnalysis(String msg) {
+        // Some error messages are formatted in multiple lines and with tabs.
+        // We clean the messages to help parse the stack traces for failure analysis.
+        // We keep at most 2 lines, otherwise the error message may be too long.
+        String[] lines = msg.split("[\r\n]+");
+        msg = lines.length >= 2 ? lines[0] + " " + lines[1] : lines[0];
+        msg = msg.replaceAll("\t", " ");
+
+        // Create a dummy exception just so we can print the stack trace.
+        TestFailure e = new TestFailure(msg);
+        StackTraceElement[] elements = e.getStackTrace();
+
+        final int callerIndex = 2; // 0=this function, 1=complain(), 2=caller
+        if (elements.length <= callerIndex) {
+            return;
+        }
+
+        // Only log the first complain message from each function.
+        // The reason is that some functions splits an error message
+        // into multiple lines and call complain() many times.
+        // We do not want a RULE for each of those calls.
+        // This means that we may miss some rules, but that
+        // is better than to create far too many rules.
+        String callerClass = elements[callerIndex].getClassName();
+        String callerMethod = elements[callerIndex].getMethodName();
+        String callerKey = callerClass + "." + callerMethod;
+        boolean isAlreadyLogged = loggedExceptions.contains(msg) || loggedExceptions.contains(callerKey);
+
+        if (!isAlreadyLogged) {
+            PrintStream stream = findOutStream();
+            stream.println("The following stacktrace is for failure analysis.");
+            e.printStackTrace(stream);
+        }
+
+        loggedExceptions.add(callerKey);
+        loggedExceptions.add(msg);
+    }
+
+    /////////////////////////////////////////////////////////////////
+
+    /**
+     * Redirect log to the given <code>stream</code>, and switch
+     * log mode to verbose.
+     * Prints errors summary to current stream, cancel current stream
+     * and switches to new stream. Turns on verbose mode for new stream.
+     *
+     * @deprecated  This method is obsolete.
+     */
+    protected synchronized void logTo(PrintStream stream) {
+        finalize(); // flush older log stream
+        out = stream;
+        verbose = true;
+    }
+
+    /////////////////////////////////////////////////////////////////
+
+    /**
+     * Print all messages from log buffer which were hidden because
+     * of non-verbose mode,
+     */
+    private synchronized void flushLogBuffer() {
+        if (!logBuffer.isEmpty()) {
+            PrintStream stream = findOutStream();
+            for (int i = 0; i < logBuffer.size(); i++) {
+                stream.println(logBuffer.elementAt(i));
+            }
+            stream.flush();
+        }
+    }
+
+    /**
+     * Return <code>out</code> stream if defined or <code>Sytem.err<code> otherwise;
+     * print a warning message when <code>System.err</code> is used first time.
+     */
+    private synchronized PrintStream findOutStream() {
+        PrintStream stream = out;
+        if (stream == null) {
+            stream = System.err;
+            if (!noOutWarned) {
+                noOutWarned = true;
+                stream.println("#>  ");
+                stream.println("#>  WARNING: switching log stream to stderr,");
+                stream.println("#>      because no output stream is assigned");
+                stream.println("#>  ");
+            };
+        };
+        stream.flush();
+        return stream;
+    }
+
+    /**
+     * Compose line to print possible prefixing it with timestamp.
+     */
+    private String composeLine(String message) {
+        if (timestamp) {
+            long time = System.currentTimeMillis();
+            long ms = time % 1000;
+            time /= 1000;
+            long secs = time % 60;
+            time /= 60;
+            long mins = time % 60;
+            time /= 60;
+            long hours = time % 24;
+            return "[" + hours + ":" + mins + ":" + secs + "." + ms + "] " + message;
+        }
+        return message;
+    }
+
+    /**
+     * Print the given <code>message</code> either to <code>out</code>
+     * stream, or to <code>System.err</code> if <code>out</code>
+     * stream is not specified.
+     */
+    private synchronized void doPrint(String message) {
+        PrintStream stream = findOutStream();
+        stream.println(composeLine(message));
+        stream.flush();
+    }
+
+    /**
+     * Print the given error <code>message</code> either to <code>out</code>
+     * stream, or to <code>System.err</code> if <code>out</code>
+     * stream is not specified.
+     */
+    private synchronized void printError(String message) {
+        // Print each line with the ERROR prefix:
+        BufferedReader br = new BufferedReader(new StringReader(message));
+        for (String line; ; ) {
+            try {
+                line = br.readLine();
+                if (line == null)
+                    break;
+                doPrint("# ERROR: " + line);
+            } catch (IOException e) {
+                throw new TestBug("Exception in Log.printError(): " + e);
+            };
+        }
+    }
+
+    /**
+     * Keep the given log <code>message</code> into <code>logBuffer</code>.
+     */
+    private synchronized void keepLog(String message) {
+        logBuffer.addElement(message);
+    }
+
+    /**
+     * Keep the given error <code>message</code> into <code>errorsBuffer</code>.
+     */
+    private synchronized void keepError(String message) {
+        errorsBuffer.addElement(message);
+    }
+
+    /**
+     * Print errors messages summary from errors buffer if any;
+     * print a warning message first.
+     */
+    private synchronized void printErrorsSummary() {
+        if (errorsBuffer.size() <= 0)
+            return;
+
+        PrintStream stream = findOutStream();
+        stream.println();
+        stream.println();
+        stream.println("#>  ");
+        stream.println("#>  SUMMARY: Following errors occured");
+        stream.println("#>      during test execution:");
+        stream.println("#>  ");
+        stream.flush();
+
+        for (Enumeration e = errorsBuffer.elements(); e.hasMoreElements(); ) {
+            printError((String) e.nextElement());
+        }
+    }
+
+    /**
+     * Print errors summary if mode is verbose, flush and cancel output stream.
+     */
+    protected void finalize() {
+        if (verbose() && isErrorsSummaryEnabled()) {
+            printErrorsSummary();
+        }
+        if (out != null)
+            out.flush();
+        out = null;
+    }
+
+    /**
+     * Perform finalization at the exit.
+     */
+    public void finalizeAtExit() {
+        finalize();
+    }
+
+    /**
+     * This class can be used as a base for each class that use <code>Log</code>
+     * for print messages and errors.
+     * <code>Logger</code> provides with ability to print such messages with
+     * specified prefix to make it possible to distinct messages printed from
+     * different sources.
+     *
+     * @see Log
+     */
+    public static class Logger {
+
+        /**
+         * Default prefix for messages.
+         */
+        public static final String LOG_PREFIX = "";
+
+        /**
+         * Log to print messages to.
+         */
+        protected Log log = null;
+
+        /**
+         * Prefix for messages.
+         */
+        protected String logPrefix = LOG_PREFIX;
+
+        /**
+         * Make <code>Logger</code> object with empty <code>Log</code> and
+         * default prefix.
+         * This method may be used only in derived class, that should specify
+         * the used <code>Log</code> object further and assign it to <code>log</code>.
+         *
+         * @see #log
+         * @see #setLogPrefix
+         */
+        protected Logger() {
+        }
+
+        /**
+         * Make <code>Logger</code> object for specified <code>Log</code>
+         * with default prefix.
+         *
+         * @see #setLogPrefix
+         */
+        public Logger(Log log) {
+            this.log = log;
+        }
+
+        /**
+         * Make <code>Logger</code> object for specified <code>Log</code> with
+         * given messages prefix.
+         */
+        public Logger(Log log, String prefix) {
+            this.log = log;
+            this.logPrefix = prefix;
+        }
+
+        /**
+         * Return <code>Log</code> object.
+         */
+        public Log getLog() {
+            return log;
+        }
+
+        /**
+         * Return output stream of this <code>Log</code> object.
+         */
+        public PrintStream getOutStream() {
+            return log.getOutStream();
+        }
+
+        /**
+         * Set prefix for printed messages.
+         */
+        public void setLogPrefix(String prefix) {
+            logPrefix = prefix;
+        }
+
+        /**
+         * Make printable message by adding <code>logPrefix<code> to it.
+         */
+        public String makeLogMessage(String message) {
+            return logPrefix + message;
+        }
+
+        /**
+         * Print trace message by invoking <code>Log.trace()</code>.
+         *
+         * @see Log#trace
+         */
+        public void trace(int level, String message) {
+            log.trace(level, makeLogMessage(message));
+        }
+
+        /**
+         * Print message by invoking <code>Log.println()</code>.
+         *
+         * @see Log#println
+         */
+        public void println(String message) {
+            log.println(makeLogMessage(message));
+        }
+
+        /**
+         * Print message by invoking <code>Log.display()</code>.
+         *
+         * @see Log#display
+         */
+        public void display(String message) {
+            log.display(makeLogMessage(message));
+        }
+
+        /**
+         * Complain about an error by invoking <code>Log.complain()</code> method.
+         *
+         * @see Log#complain
+         */
+        public void complain(String message) {
+            log.complain(makeLogMessage(message));
+        }
+
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/NativeUtils.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2006, 2018, 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.
+ */
+package nsk.share;
+
+public class NativeUtils {
+    static {
+        System.loadLibrary("native_utils");
+    }
+
+    public static native long getCurrentPID();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/ObjectInstancesManager.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,232 @@
+/*
+ * Copyright (c) 2006, 2018, 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.
+ */
+package nsk.share;
+
+import java.util.*;
+
+/*
+ *  Class create/delete instances with given reference type and given referrers number
+ */
+public class ObjectInstancesManager
+{
+        public static String STRONG_REFERENCE = "STRONG";
+        public static String WEAK_REFERENCE = "WEAK";
+        public static String SOFT_REFERENCE = "SOFT";
+        public static String PHANTOM_REFERENCE = "PHANTOM";
+        public static String JNI_GLOBAL_REFERENCE = "JNI_GLOBAL";
+        public static String JNI_LOCAL_REFERENCE = "JNI_LOCAL";
+        public static String JNI_WEAK_REFERENCE = "JNI_WEAK";
+
+        // used to create references of all types
+        private static String USE_ALL_REFERENCE_TYPES = "ALL_REFERENCE_TYPES";
+
+        private Map<String, Collection<ReferringObjectSet>> instances = new TreeMap<String, Collection<ReferringObjectSet>>();
+
+        public static Set<String> primitiveArrayClassNames = new HashSet<String>();
+
+        static
+        {
+                primitiveArrayClassNames.add("boolean[]");
+                primitiveArrayClassNames.add("byte[]");
+                primitiveArrayClassNames.add("char[]");
+                primitiveArrayClassNames.add("int[]");
+                primitiveArrayClassNames.add("long[]");
+                primitiveArrayClassNames.add("float[]");
+                primitiveArrayClassNames.add("double[]");
+        }
+
+
+        public static Set<String> allReferenceTypes = new HashSet<String>();
+
+        static
+        {
+                allReferenceTypes.add(ObjectInstancesManager.STRONG_REFERENCE);
+                allReferenceTypes.add(ObjectInstancesManager.WEAK_REFERENCE);
+                allReferenceTypes.add(ObjectInstancesManager.SOFT_REFERENCE);
+                allReferenceTypes.add(ObjectInstancesManager.PHANTOM_REFERENCE);
+                allReferenceTypes.add(ObjectInstancesManager.JNI_GLOBAL_REFERENCE);
+                allReferenceTypes.add(ObjectInstancesManager.JNI_LOCAL_REFERENCE);
+                allReferenceTypes.add(ObjectInstancesManager.JNI_WEAK_REFERENCE);
+        }
+
+        public static boolean isWeak(String type) {
+            return !(type.equals(ObjectInstancesManager.JNI_GLOBAL_REFERENCE)
+                    || type.equals(ObjectInstancesManager.JNI_LOCAL_REFERENCE)
+                    || type.equals(ObjectInstancesManager.STRONG_REFERENCE));
+
+        }
+
+        public static Log log;
+
+        public ObjectInstancesManager(Log log)
+        {
+                ObjectInstancesManager.log = log;
+        }
+
+        // delete a given number of referrers
+        public void deleteReferrers(String className, int referrersCount, Set<String> referrerTypes)
+        {
+                Collection<ReferringObjectSet> objectInstances;
+
+                objectInstances = instances.get(className);
+
+                if(objectInstances == null)
+                {
+                        log.display("Error command 'deleteObjectInstances' is requsted: instances of class " + className + " was not created");
+                        System.exit(Consts.JCK_STATUS_BASE + Consts.TEST_FAILED);
+                        return;
+                }
+
+                Iterator<ReferringObjectSet> iterator = objectInstances.iterator();
+
+                while(iterator.hasNext())
+                {
+                        ReferringObjectSet debugeeObjectReference = iterator.next();
+                        if (referrerTypes.isEmpty() || referrerTypes.contains(debugeeObjectReference.getReferenceType())) {
+                                debugeeObjectReference.delete(referrersCount);
+
+                                if(debugeeObjectReference.getReferrerCount() == 0)
+                                        iterator.remove();
+                        }
+                }
+        }
+
+        // delete all object referrers, it is equal to make object unreacheable
+        public void deleteAllReferrers(int count, String className)
+        {
+                Collection<ReferringObjectSet> objectInstances;
+
+                objectInstances = instances.get(className);
+
+                if(objectInstances == null)
+                {
+                        throw new TestBug("Command 'deleteObjectInstances' is requsted: instances of class " + className + " was not created");
+                }
+
+                Iterator<ReferringObjectSet> iterator = objectInstances.iterator();
+
+                if(count == 0)
+                        count = objectInstances.size();
+
+                for(int i = 0; i < count; i++)
+                {
+                        ReferringObjectSet debugeeObjectReference = iterator.next();
+                        debugeeObjectReference.deleteAll();
+
+                        iterator.remove();
+                }
+        }
+
+        // create object instance with referrers of all possible types
+        public void createAllTypeReferences(String className, int count)
+        {
+                createReferences(count, className, 1, allReferenceTypes);
+        }
+
+        // create a given number of object instances with given number of referrers
+        public void createReferences(int count, String className, int referrerCount, Set<String> referrerTypes)
+        {
+                Collection<ReferringObjectSet> objectInstances;
+
+                Class klass = null;
+
+                if(!primitiveArrayClassNames.contains(className))
+                {
+                        try
+                        {
+                                klass = Class.forName(className);
+                        }
+                        catch(ClassNotFoundException e)
+                        {
+                                log.display("Can't find class: " + className);
+                                System.exit(Consts.JCK_STATUS_BASE + Consts.TEST_FAILED);
+                                return;
+                        }
+                }
+
+                objectInstances = instances.get(className);
+
+                if(objectInstances == null)
+                {
+                        objectInstances = new ArrayList<ReferringObjectSet>();
+                        instances.put(className, objectInstances);
+                }
+
+                for(int i = 0; i < count; i++)
+                {
+                        try
+                        {
+                                Object instance;
+
+                                if(!primitiveArrayClassNames.contains(className))
+                                {
+                                        instance = klass.newInstance();
+                                }
+                                else
+                                {
+                                        instance = createPrimitiveTypeArray(className);
+                                }
+
+                                for(String type : referrerTypes) {
+                                        objectInstances.add(new ReferringObjectSet(instance, referrerCount, type));
+                                }
+                        }
+                        catch(Exception e)
+                        {
+                                log.display("Unexpected exception: " + e);
+                                System.exit(Consts.JCK_STATUS_BASE + Consts.TEST_FAILED);
+                        }
+                }
+        }
+
+        public Object createPrimitiveTypeArray(String typeName)
+        {
+                int arraySize = 1;
+
+                if(typeName.equals("boolean[]"))
+                        return new boolean[arraySize];
+                else
+                if(typeName.equals("byte[]"))
+                        return new byte[arraySize];
+                else
+                if(typeName.equals("char[]"))
+                        return new char[arraySize];
+                else
+                if(typeName.equals("int[]"))
+                        return new int[arraySize];
+                else
+                if(typeName.equals("long[]"))
+                        return new long[arraySize];
+                else
+                if(typeName.equals("float[]"))
+                        return new float[arraySize];
+                else
+                if(typeName.equals("double[]"))
+                        return new double[arraySize];
+                else
+                {
+                        throw new TestBug("Invalid primitive type array type name: " + typeName);
+                }
+        }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/Oddity.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2001, 2018, 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.
+ */
+
+package nsk.share;
+
+/**
+ * Oddity exception is used to simulate C/C++ style <code>assert()</code>
+ * facility. It is thrown when an internal contradiction is revealed, which
+ * may do not indicate a bug in the JDI implementation or in the test.
+ */
+public class Oddity extends Failure {
+    /** Explain particular oddity. */
+    public Oddity (String message) {
+        super(message);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/Pair.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2011, 2018, 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.
+ */
+package nsk.share;
+
+public class Pair<A, B> {
+    final public A first;
+    final public B second;
+
+    private Pair(A first, B second) {
+        this.first = first;
+        this.second = second;
+    }
+
+    public static <A, B> Pair<A, B> of(A first, B second) {
+        return new Pair<A, B>(first, second);
+    }
+
+    @Override
+    public String toString() {
+        return "(" + first + ", " + second + ")";
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/Paragrep.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,176 @@
+/*
+ * Copyright (c) 2002, 2018, 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.
+ */
+
+package nsk.share;
+
+import java.util.*;
+import java.util.regex.*;
+
+/**
+ * Weak emulator of perl's grep function with very small functionality.
+ * This class does not use java.util.regexp classes which appear in
+ * JDK1.4 API.
+ *
+ * @see Grep
+ */
+
+public class Paragrep {
+
+    String[] stringArray;
+    /**
+     * Takes String array as character sequence for matching the pattern.
+     */
+    public Paragrep (String[] stringArray) {
+        this.stringArray = stringArray;
+    }
+
+    /**
+     * Returns number of non-interleaved occurences of the pattern string.
+     */
+    public int find (String pattern) {
+        if (pattern.length() == 0) {
+            throw new Failure("Empty string as input parameter for Grep.find(pattern) method");
+        }
+        int counter = 0;
+        for (int i = 0; i < stringArray.length; i++) {
+
+            String string = stringArray[i];
+            if (string != null) {
+                // Find all non-interleaved occurences of pattern in this string
+                for (int ind = 0; ind < string.length(); ) {
+                    int k = 0;
+                    if ((k = string.indexOf(pattern, ind)) >= 0) {
+                       counter++;
+                       ind = k + pattern.length();
+                    } else {
+                       break;
+                    }
+                }
+            }
+        }
+        return counter;
+    }
+
+    /**
+     * Returns all string in <code>stringArray</code> which have
+     * occurences of the pattern string.
+     */
+    public String[] findStrings (String pattern) {
+        if (pattern.length() == 0) {
+            throw new Failure("Empty string as input parameter for Grep.find(pattern) method");
+        }
+        Vector<String> v = new Vector<String>();
+        for (int i = 0; i < stringArray.length; i++) {
+            String string = stringArray[i];
+            if (string != null && string.indexOf(pattern) >= 0) {
+               v.add(string);
+            }
+        }
+        String[] result = new String[v.size()];
+        v.toArray(result);
+        return result;
+    }
+
+    /**
+     * Returns first string of stringArray which contains
+     * the pattern string or empty string othrewise.
+     */
+    public String findFirst (String pattern) {
+        if (pattern.length() == 0) {
+            throw new Failure("Empty string as input parameter for Paragrep.findFirst(pattern) method");
+        }
+        String result = "";
+        for (int i = 0; i < stringArray.length; i++) {
+            String string = stringArray[i];
+            if (string != null) {
+                if (string.indexOf(pattern) >= 0) {
+                    result = string;
+                    break;
+                }
+            }
+        }
+        return result;
+    }
+
+    /**
+     * Returns first string of stringArray which contains
+     * all of the pattern strings or empty string otherwise.
+     */
+    public String findFirst (Vector<String> patternVector) {
+        if (patternVector.isEmpty()) {
+            throw new Failure("Empty vector as input parameter for Paragrep.findFirst(patternVector) method");
+        }
+        String[] patterns = new String[patternVector.size()];
+        patternVector.toArray(patterns);
+        String result = "";
+        for (int i = 0; i < stringArray.length; i++) {
+            String string = stringArray[i];
+            if (string != null && string.length() > 0) {
+                for (int j = 0; j < patterns.length; j++) {
+                    String pattern = patterns[j];
+                    if (string.indexOf(pattern) >= 0) {
+                        if (j + 1 == patterns.length) {
+                            // found all patterns in the current string
+                            result = string;
+                            i = stringArray.length;
+                        }
+                    } else {
+                        break;
+                    }
+                }
+            }
+        }
+        return result;
+    }
+
+    /**
+     * Returns count of strings in stringArray which contain
+     * all of the pattern strings.
+     */
+    public int find (Vector<String> patternVector) {
+        if (patternVector.isEmpty()) {
+            throw new Failure("Empty vector as input parameter for Paragrep.find(patternVector) method");
+        }
+        String[] patterns = new String[patternVector.size()];
+        patternVector.toArray(patterns);
+        int counter = 0;
+
+        for (int i = 0; i < stringArray.length; i++) {
+            String string = stringArray[i];
+            if (string != null && string.length() > 0) {
+                for (int j = 0; j < patterns.length; j++) {
+                    String pattern = patterns[j];
+                    if (string.indexOf(pattern) >= 0) {
+                        if (j + 1 == patterns.length) {
+                            // found all patterns in the current string
+                            counter++;
+                        }
+                    } else {
+                        break;
+                    }
+                }
+            }
+        }
+        return counter;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/PrintProperties.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2005, 2018, 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.
+ */
+
+package nsk.share;
+
+import java.util.Properties;
+
+/**
+ * This program prints system properties.
+ */
+public class PrintProperties {
+        public static void main(String[] args) {
+                Properties pr = System.getProperties();
+                switch (args.length) {
+                case 0:
+                        pr.list(System.out);
+                        System.exit(0);
+                case 1:
+                        String value = pr.getProperty(args[0]);
+                        if (value == null) {
+                                System.err.println("Not found");
+                                System.exit(1);
+                        } else {
+                                System.out.println(value);
+                                System.exit(0);
+                        }
+                default:
+                        System.out.println("Usage:");
+                        System.out.println("    PrintProperties");
+                        System.out.println("    PrintProperties <property name>");
+                        System.exit(255);
+                }
+        }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/RASagent.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,376 @@
+/*
+ * Copyright (c) 2002, 2018, 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.
+ */
+
+package nsk.share;
+
+import java.io.*;
+import java.lang.reflect.Method;
+import java.util.*;
+
+/**
+ * Class used as an agent for Java serviceability reliability testing (RAS).
+ * It sets different RAS options and/or modes for a special agent which
+ * actually performs the specified RAS testing.<br>
+ * The agent recognizes arguments, started with ''<code>-ras.</code>''. They
+ * may be as follows:<p>
+ * <li><code>-ras.help</code> - print usage message and exit
+ * <li><code>-ras.verbose</code> - verbose mode
+ * <li><code>-ras.invoke_run</code> - invoke the method <i>run(String[],PrintStream)</i>
+ * of the test instead of <i>main(String[])</i> which is invoked by default.
+ * <li><code>-ras.hotswap=&lt;stress_level&gt;</code> - enable JVMTI hotswap of
+ * the currently running test classes. Here are the possible HotSwap stress
+ * levels:<br>
+ * 0 - HotSwap off<br>
+ * 2 - HotSwap tested class in every JVMTI method entry event of running test
+ * (default mode)<br>
+ * 20 - HotSwap tested class in every JVMTI method entry event of every class<br>
+ * 3 - HotSwap tested class in every JVMTI single step event of running test<br>
+ * 4 - HotSwap tested class in every JVMTI exception event of running test<br>
+ * 40 - HotSwap tested class in every JVMTI exception event of every class<p>
+ */
+public class RASagent {
+    static final int HOTSWAP_OFF = 0;
+    static final int HOTSWAP_EVERY_METHOD_ENTRY = 2;
+    static final int HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS = 20;
+    static final int HOTSWAP_EVERY_SINGLE_STEP = 3;
+    static final int HOTSWAP_EVERY_EXCEPTION = 4;
+    static final int HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS = 40;
+
+    // path to the directory with class files of the invoked test
+    static String clfBasePath = null;
+
+    private static boolean verbose = false;
+
+    private static PrintStream out;
+
+    native static int setHotSwapMode(boolean vrb, int stress_lev,
+        String shortName);
+
+    public static void main(String argv[]) {
+        System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE);
+    }
+
+    public static int run(String argv[], PrintStream out) {
+        return new RASagent().runThis(argv, out);
+    }
+
+    private int runThis(String argv[], PrintStream out) {
+        int skipArgs = 1; // number of arguments which must be skipped
+                          // for the invoked test
+        boolean invokeRun = false; // invoke the method "main" by default
+        int hotSwapMode = HOTSWAP_EVERY_METHOD_ENTRY; // HotSwap default stress level
+        int res;
+        String hotSwapModeName = "HOTSWAP_EVERY_METHOD_ENTRY";
+
+        RASagent.out = out;
+
+        if (argv.length != 0) {
+            // parse arguments for the RASagent and then skip them
+            while(argv[skipArgs-1].startsWith("-ras.")) {
+                if (argv[skipArgs-1].equals("-ras.verbose")) {
+                    verbose = true;
+                } else if (argv[skipArgs-1].equals("-ras.help")) {
+                    printHelp();
+                    return Consts.TEST_FAILED;
+                } else if (argv[skipArgs-1].equals("-ras.invoke_run")) {
+                    invokeRun = true;
+                } else if (argv[skipArgs-1].startsWith("-ras.hotswap=")) {
+                    try {
+                        hotSwapMode = Integer.parseInt(
+                           argv[skipArgs-1].substring(argv[skipArgs-1].lastIndexOf("=")+1));
+                    } catch (NumberFormatException e) {
+                        e.printStackTrace();
+                        out.println("\nERROR: RASagent: specified HotSwap mode \""
+                            + hotSwapMode + "\" is not an integer");
+                        printHelp();
+                        return Consts.TEST_FAILED;
+                    }
+                    switch(hotSwapMode) {
+                        case HOTSWAP_EVERY_METHOD_ENTRY:
+                            hotSwapModeName = "HOTSWAP_EVERY_METHOD_ENTRY";
+                            break;
+                        case HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS:
+                            hotSwapModeName = "HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS";
+                            break;
+                        case HOTSWAP_EVERY_SINGLE_STEP:
+                            hotSwapModeName = "HOTSWAP_EVERY_SINGLE_STEP";
+                            break;
+                        case HOTSWAP_EVERY_EXCEPTION:
+                            hotSwapModeName = "HOTSWAP_EVERY_EXCEPTION";
+                            break;
+                        case HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS:
+                            hotSwapModeName = "HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS";
+                            break;
+                        default:
+                            out.println("\nERROR: RASagent: specified HotSwap mode \""
+                                + hotSwapMode + "\" is unrecognized");
+                            printHelp();
+                            return Consts.TEST_FAILED;
+                    }
+                }
+                skipArgs++;
+            }
+
+            String shortTestName = getTestNameAndPath(argv[skipArgs-1]);
+
+            display("\n#### RASagent: setting hotswap mode \""
+                + hotSwapModeName + "\" for class \""
+                + shortTestName + "\" ...");
+            if ((res = setHotSwapMode(verbose, hotSwapMode, shortTestName)) != 0) {
+                out.println("\nERROR: RASagent: unable to set HotSwap stress level for \""
+                    + shortTestName + "\", exiting");
+                return Consts.TEST_FAILED;
+            }
+            display("\n#### RASagent: ... setting hotswap mode done");
+
+            try {
+                Class testCls = Class.forName(argv[skipArgs-1]);
+                display("\n#### RASagent: main class \""
+                    + testCls.toString() + "\" loaded");
+
+                // copy arguments for the invoked test
+                String args[] = new String[argv.length-skipArgs];
+                System.arraycopy(argv, skipArgs, args, 0, args.length);
+
+                // invoke the test
+                if (invokeRun)
+                    return invokeRunMethod(testCls, args);
+                else
+                    return invokeMainMethod(testCls, args);
+            } catch(ClassNotFoundException e) {
+                // just pass: the invoked test is already a RAS specific one
+                out.println("\nWARNING: the test was not really run due to the following error:"
+                    + "\n\tunable to get the Class object for \""
+                    + argv[skipArgs-1] + "\"\n\tcaught: " + e);
+                return Consts.TEST_PASSED;
+            }
+
+        } else {
+            out.println("\nERROR: RASagent: required test name is absent in parameters list");
+            return Consts.TEST_FAILED;
+        }
+    }
+
+    /**
+     * Verify that test's class file exists with a path given as a parameter
+     * and, if so, store that path in the static field "clfBasePath".
+     */
+    private boolean pathValid(String pathToCheck, String testName) {
+        String fullPath = pathToCheck + File.separator
+            + testName.replace('.', File.separatorChar) + ".class";
+        File classFile = null;
+
+        display("\n#### RASagent: verifying class path\n<RASagent>\t"
+            + pathToCheck + " ...");
+        try {
+            classFile = new File(fullPath);
+        } catch (NullPointerException e) {
+            e.printStackTrace();
+            out.println("\nERROR: RASagent: verification of class file "
+                + fullPath + " failed: caught " + e);
+            System.exit(Consts.JCK_STATUS_BASE + Consts.TEST_FAILED);
+        }
+
+        if (classFile.exists()) {
+            clfBasePath = pathToCheck;
+            display("<RASagent>\tthe class file exists:\n<RASagent>\t\t"
+                + fullPath + "\n<RASagent>\tclass file base directory found:\n"
+                + "<RASagent>\t\t" + clfBasePath
+                + "\n#### RASagent: ... class path verification done\n");
+            return true;
+        }
+        else {
+            display("<RASagent>\tno class file at location :\n\t\t"
+                + fullPath
+                + "\n#### RASagent: ... class path verification done\n");
+            return false;
+        }
+    }
+
+    /**
+     * Get short name of an invoked test (i.e. without package name) and
+     * store path to the directory with the test's class files.
+     */
+    private String getTestNameAndPath(String testName) {
+        String shortTestName = testName;
+        String packageName = "";
+
+        // if '.' occurs, it means that current test is inside a package
+        if (testName.lastIndexOf(".") != -1) {
+            shortTestName = testName.substring(testName.lastIndexOf(".")+1);
+            packageName = testName.substring(0, testName.lastIndexOf("."));
+        }
+
+        StringTokenizer clPathes = new StringTokenizer(
+            System.getProperty("java.class.path"), File.pathSeparator);
+
+        while(clPathes.hasMoreTokens()) {
+            String clPath = clPathes.nextToken();
+
+            // trying to load a class file defining the current test from
+            // this entry of "java.class.path": the class file may locate
+            // at the test's work directory or if it's already compiled,
+            // at any directory in classpath
+            if (pathValid(clPath, testName))
+                return shortTestName;
+        }
+
+        // directory with the test's class files was not found.
+        // Actually, it means that the invoked test has own Java
+        // options such as, for example, "-verify"
+        out.println("\nWARNING: the test was not really run due to the following reason:"
+            + "\n\tthe invoked test has the own Java option: "
+            + testName);
+        System.exit(Consts.JCK_STATUS_BASE + Consts.TEST_PASSED);
+
+        return null; // fake return for too smart javac
+    }
+
+    /**
+     * Invoke the method <i>main(String[])</i> of the test.
+     */
+    private int invokeMainMethod(Class testCls, String args[]) {
+        Class[] methType = { String[].class };
+        Object[] methArgs = { args };
+
+        return invokeMethod(testCls, "main", methType, methArgs);
+    }
+
+    /**
+     * Invoke the method <i>run(String[], PrintStream)</i> of the test.
+     */
+    private int invokeRunMethod(Class testCls, String args[]) {
+        Class[] methType = { String[].class, PrintStream.class };
+        Object[] methArgs = { args, out };
+
+        return invokeMethod(testCls, "run", methType, methArgs);
+    }
+
+    /**
+     * Low level invocation of the test.
+     */
+    private int invokeMethod(Class<?> testCls, String methodName,
+            Class methType[], Object methArgs[]) {
+
+        try {
+            Method testMeth = testCls.getMethod(methodName, methType);
+            display("\n#### RASagent: invoking method \""
+                + testMeth.toString() + "\" ...");
+
+            Object result = testMeth.invoke(null, methArgs);
+
+            display("\n#### RASagent: ... invocation of \""
+                + testMeth.toString() + "\" done");
+            if (result instanceof Integer) {
+                Integer retCode = (Integer) result;
+                return retCode.intValue();
+            }
+        } catch(NoSuchMethodException e) {
+            e.printStackTrace();
+            out.println("\nFAILURE: RASagent: unable to get method \""
+                + methodName + "\" in class "
+                + testCls + "\n\tcaught " + e);
+            return Consts.TEST_FAILED;
+        } catch(Exception e) {
+            e.printStackTrace();
+            out.println("\nFAILURE: RASagent: caught during invokation of the test class "
+                + testCls + " " + e);
+            return Consts.TEST_FAILED;
+        }
+
+        return -1;
+    }
+
+    /**
+     * Load class bytes for HotSwap.
+     */
+    static byte[] loadFromClassFile(String signature) {
+        String testPath = clfBasePath + File.separator + signature.substring(
+                1, signature.length()-1).replace('/', File.separatorChar) + ".class";
+        File classFile = null;
+
+        display("\n#### RASagent: looking for class file\n<RASagent>\t"
+            + testPath + " ...");
+
+        try {
+            classFile = new File(testPath);
+        } catch (NullPointerException e) {
+            out.println("\nFAILURE: RASagent: path name to the redefining class file is null");
+        }
+
+        display("\n#### RASagent: loading " + classFile.length()
+            + " bytes from class file "+ testPath + " ...");
+        byte[] buf = new byte[(int) classFile.length()];
+        try {
+            InputStream in = new FileInputStream(classFile);
+            in.read(buf);
+            in.close();
+        } catch(FileNotFoundException e) {
+            e.printStackTrace();
+            out.println("\nFAILURE: RASagent: loadFromClassFile: file " +
+                classFile.getName() + " not found");
+            System.exit(Consts.JCK_STATUS_BASE + Consts.TEST_FAILED);
+        } catch (Exception e) {
+            e.printStackTrace();
+            out.println("\nFAILURE: RASagent: unable to load bytes from the file:\n");
+            out.println("\t" + testPath + ": caught " + e);
+            System.exit(Consts.JCK_STATUS_BASE + Consts.TEST_FAILED);
+        }
+
+        display("\n#### RASagent: ... " + classFile.length() + " bytes loaded");
+
+        return buf;
+    }
+
+    /**
+     * This method is used in verbose mode. It prints paramter string only
+     * in case of verbose mode.
+     */
+    private static void display(String msg) {
+        if (verbose)
+            out.println(msg);
+    }
+
+    /**
+     * This method prints out RASagent usage message.
+     */
+    private static void printHelp() {
+        out.println("\nRASagent usage: RASagent [option, ...] test" +
+            "\n\t-ras.help                 print this message and exit" +
+            "\n\t-ras.verbose              verbose mode (off by default)" +
+            "\n\t-ras.hotswap=mode         enable HotSwap of the running test classes" +
+            "\n\t\twhere mode is:" +
+            "\n\t\t\t" + HOTSWAP_EVERY_METHOD_ENTRY
+                + " - hotswap tested class in its every method entry event" +
+            "\n\t\t\t" + HOTSWAP_EVERY_METHOD_ENTRY_FOR_EVERY_CLASS
+                + " - hotswap tested class in every method entry event for every class" +
+            "\n\t\t\t" + HOTSWAP_EVERY_SINGLE_STEP
+                + " - hotswap tested class in its every single step event" +
+            "\n\t\t\t" + HOTSWAP_EVERY_EXCEPTION
+                + " - hotswap tested class in its every exception event" +
+            "\n\t\t\t" + HOTSWAP_EVERY_EXCEPTION_FOR_EVERY_CLASS
+                + " - hotswap tested class in every exception event for every class\n" +
+            "\n\t-ras.invoke_run           invoke the method run() of the test" +
+            "\n\t\tinstead of main() by default");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/README	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,128 @@
+Copyright (c) 2003, 2018, 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.
+
+---------------------------------------------------------------------------------
+
+This directory contains source files of NSK tests framework
+shared between all NSK tests.
+
+Files located directly in this directory provide general support
+for all tests.
+
+Files in the subdirectories provide specific support for tests of
+particular subsuites.
+
+---------------------------------------------------------------------------------
+
+Short description of files:
+
+    common exceptions:
+        Failure,java, TestBug.java, Oddity.java
+    common constants:
+        Consts.java
+    parsing command line arguments:
+        ArgumentPareser.java
+    output of errors and messages:
+        Log.java
+    process running:
+        LocalProcess.java, IORedirector.java
+    class loading/unloading:
+        DummyClassLoader.java, ZipClassLoader.java,
+        CustomClassLoader.java, ClassUnloder.java
+    objects finalization:
+        Finalizable.java, FinalizableObject.java, Finalizer.java
+    threads synchronization:
+        Wicket.java
+    text processing:
+        Grep.java, Paragrep.java
+    timeouts handling:
+        Harakiri.java, TimeoutHandler.java
+    tree structures support:
+        Denotation.java, TreeNodesDenotation.java
+    RAS mode support:
+        RASagent.java, JVMTIagent.c
+    JVMDI tests support:
+        JVMDITools.h, JVMDITools.c
+
+Short description of subdirectories:
+
+    Alien       - support for accessing external tests (JCK)
+    native      - support for native part of NSK tests
+    jni         - support for JNI tests and accessing JNI API
+    jvmti       - support for JVMTI tests and accessing JVMTI API
+    jpda        - support for two-VMs JPDA tests
+    jdwp        - support for JDWP tests and accessing JDWP API
+    jdi         - support for JDI tests and accesing JDI API
+    jdb         - support for JDB tests and accessing JDB tool
+    monitoring  - support for monitoring tests and accessing Java Monitoring&Management API
+    sysdict     - support for System Dictionary tests
+    gc          - support for GC tests
+    regression  - support for regression tests for known bugs
+    split_verifier - support for Split Verifier tests
+
+For more detailed description see README files in subdirectories.
+
+---------------------------------------------------------------------------------
+
+Naming conventions
+
+Classes:
+
+    All shared classes are groupped into packages to prevent
+    name collision.
+
+    All classes exported directly from this directory are
+    of package:
+
+        nsk.share
+
+    All classes exported from subdirectories are of particular
+    subpackage, e.g.:
+
+        nsk.share.jpda
+        nsk.share.jdwp
+        nsk.share.jdi
+        nsk.share.jdb
+        nsk.share.monitoring
+        nsk.share.sysdict
+
+Native functions and macroses:
+
+    Most native functions have special prefix to prevent linking collisions.
+    Most macroses also have special prefix and are wrote in upper register.
+
+    Here is typical naming scheme used for native functions and macroses:
+
+        share/native
+            functions: nsk_*
+            macroses:  NSK_*
+
+        share/jni
+            functions: nsk_jni_*
+            macroses:  NSK_JNI_*
+
+        share/jvmti
+            functions: nsk_jvmti_*
+            macroses:  NSK_JVMTI_*
+
+    However, some native functions and macroses do not follow this scheme,
+    in order to preserve compatibility with old tests.
+
+---------------------------------------------------------------------------------
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/ReferringObject.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,265 @@
+/*
+ * Copyright (c) 2006, 2018, 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.
+ */
+package nsk.share;
+
+import java.lang.ref.PhantomReference;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.SoftReference;
+import java.lang.ref.WeakReference;
+
+/*
+ * This class create/delete reference with given type.
+ *
+ * Supported reference types are:
+ * - strong
+ * - soft
+ * - weak
+ * - phantom
+ * - jni local
+ * - jni global
+ * - jni weak
+ */
+public class ReferringObject
+{
+        static
+        {
+                System.loadLibrary("JNIreferences");
+        }
+
+        public final static int maxJNIGlobalReferences = 1000;
+        public final static int maxJNIWeakReferences = 1000;
+
+        private Object reference;
+
+        private String referenceType;
+
+        //used for storing jni global and jni weak references
+        private int referenceIndex;
+
+        public ReferringObject(Object object, String referenceType)
+        {
+                this.referenceType = referenceType;
+
+                if(referenceType.equals(ObjectInstancesManager.STRONG_REFERENCE))
+                {
+                        createStrongReference(object);
+                }
+                else
+                if(referenceType.equals(ObjectInstancesManager.SOFT_REFERENCE))
+                {
+                        createSoftReference(object);
+                }
+                else
+                if(referenceType.equals(ObjectInstancesManager.WEAK_REFERENCE))
+                {
+                        createWeakReference(object);
+                }
+                else
+                if(referenceType.equals(ObjectInstancesManager.PHANTOM_REFERENCE))
+                {
+                        createPhantomReference(object);
+                }
+                else
+                if(referenceType.equals(ObjectInstancesManager.JNI_GLOBAL_REFERENCE))
+                {
+                        createJNIGlobalReference(object);
+                }
+                else
+                if(referenceType.equals(ObjectInstancesManager.JNI_LOCAL_REFERENCE))
+                {
+                        createJNILocalReference(object);
+                }
+                else
+                if(referenceType.equals(ObjectInstancesManager.JNI_WEAK_REFERENCE))
+                {
+                        createJNIWeakReference(object);
+                }
+                else
+                        throw new IllegalArgumentException("Invalid reference type: " + referenceType);
+        }
+
+        public void delete()
+        {
+                if(referenceType == null)
+                {
+                        throw new TestBug("Reference type is null");
+                }
+
+                if(referenceType.equals(ObjectInstancesManager.SOFT_REFERENCE))
+                {
+                        if(reference == null)
+                        {
+                                throw new TestBug("Reference is null for SoftReference");
+                        }
+
+                        if(((SoftReference)reference).get() == null)
+                        {
+                     //           throw new TestBug("Test execution error: SoftReference was collected");
+                        }
+                }
+                else
+                if(referenceType.equals(ObjectInstancesManager.WEAK_REFERENCE))
+                {
+                        if(reference == null)
+                        {
+                                throw new TestBug("Reference is null for WeakReference");
+                        }
+
+                        if(((WeakReference)reference).get() == null)
+                        {
+                       //         throw new TestBug("Test execution error: WeakReference was collected");
+                        }
+                }
+                else
+                if(referenceType.equals(ObjectInstancesManager.PHANTOM_REFERENCE))
+                {
+                        if(reference == null)
+                        {
+                                throw new TestBug("Reference is null for PhantomReference");
+                        }
+                }
+                else
+                if(referenceType.equals(ObjectInstancesManager.JNI_GLOBAL_REFERENCE))
+                {
+                        deleteJNIGlobalReferenceNative(referenceIndex);
+                }
+                else
+                if(referenceType.equals(ObjectInstancesManager.JNI_LOCAL_REFERENCE))
+                {
+                        deleteJNILocalReference();
+                }
+                else
+                if(referenceType.equals(ObjectInstancesManager.JNI_WEAK_REFERENCE))
+                {
+                    try {
+                        deleteJNIWeakReferenceNative(referenceIndex);
+                    } catch (Throwable t)
+                    {
+
+                    }
+                }
+
+                reference = null;
+        }
+
+        private void createStrongReference(Object object)
+        {
+                reference = object;
+        }
+
+        private void createSoftReference(Object object)
+        {
+                reference = new SoftReference<Object>(object);
+        }
+
+        private void createWeakReference(Object object)
+        {
+                reference = new WeakReference<Object>(object);
+        }
+
+        private void createPhantomReference(Object object)
+        {
+                reference = new PhantomReference<Object>(object, new ReferenceQueue<Object>());
+        }
+
+        private void createJNIGlobalReference(Object object)
+        {
+                referenceIndex = createJNIGlobalReferenceNative(object, maxJNIGlobalReferences);
+
+                if(referenceIndex < 0)
+                {
+                        throw new TestBug("Error on creation of JNI_Global reference, Possible number of JNI_Global references exceeded max available value!");
+                }
+        }
+
+        /*
+         * Since jni local reference valid only for duration of native method call, to create jni local reference
+         * special thread is created which enter in native method, create jni local reference and wait
+         */
+        private void createJNILocalReference(Object object)
+        {
+                this.reference = object;
+
+                jniLocalReferenceThread = new JNILocalReferenceThread();
+                jniLocalReferenceThread.start();
+
+                // wait till JNI local reference will be created
+                jniLocalReferenceThread.createWhicket.waitFor();
+
+                reference = null;
+        }
+
+        private void deleteJNILocalReference()
+        {
+                // notify JNI method that JNI local reference is not needed any more and could be released
+                jniLocalReferenceThread.deleteWhicket.unlock();
+
+                try
+                {
+                        jniLocalReferenceThread.join(1000 * 60 * 2);
+
+                        if(jniLocalReferenceThread.isAlive())
+                        {
+                                throw new TestBug("JNI_Local_Reference thread can't finish execution");
+                        }
+                }
+                catch(InterruptedException e)
+                {
+                        throw new TestBug("deleteJNILocalReference was interrupted");
+                }
+        }
+
+        private void createJNIWeakReference(Object object)
+        {
+                referenceIndex = createJNIWeakReferenceNative(object, maxJNIWeakReferences);
+
+                if(referenceIndex < 0)
+                {
+                        throw new TestBug("Error on creation of JNI_Weak reference. Possible number of JNI_Weak references exceeded max available value!");
+                }
+        }
+
+        class JNILocalReferenceThread
+                extends Thread
+        {
+                Wicket createWhicket = new Wicket();
+                Wicket deleteWhicket = new Wicket();
+
+                public void run()
+                {
+                        createJNILocalReferenceNative(reference, createWhicket, deleteWhicket);
+                }
+        }
+
+        private JNILocalReferenceThread jniLocalReferenceThread;
+
+        private native int createJNIGlobalReferenceNative(Object object, int maxJNIGlobalReferences);
+
+        private native void deleteJNIGlobalReferenceNative(int index);
+
+        private native void createJNILocalReferenceNative(Object object, Wicket createWhicket, Wicket deleteWhicket);
+
+        private native int createJNIWeakReferenceNative(Object object, int maxJNIWeakReferences);
+
+        private native void deleteJNIWeakReferenceNative(int index);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/ReferringObjectSet.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2006, 2018, 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.
+ */
+package nsk.share;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+/*
+ *  Class create a number of referrers to given object
+ */
+public class ReferringObjectSet
+{
+        private Collection<ReferringObject> referringObjects;
+        private String referenceType;
+
+        public ReferringObjectSet(Object object, int referringCount, String referenceType)
+        {
+                this.referenceType = referenceType;
+                referringObjects = new ArrayList<ReferringObject>(referringCount);
+
+                for(int i = 0; i < referringCount; i++)
+                        referringObjects.add(new ReferringObject(object, referenceType));
+        }
+
+        public void delete(int count)
+        {
+                if((count < 0) || (count > referringObjects.size()))
+                {
+                        throw new TestBug("Invalid 'count' value: " + count + ", size=" + referringObjects.size());
+                }
+
+                Iterator<ReferringObject> iterator = referringObjects.iterator();
+
+                for(int i = 0; i < count; i++)
+                {
+                        ReferringObject referringObject = iterator.next();
+                        referringObject.delete();
+
+                        iterator.remove();
+                }
+        }
+
+        public void deleteAll()
+        {
+                delete(referringObjects.size());
+        }
+
+        public String getReferenceType() {
+            return referenceType;
+        }
+
+        public int getReferrerCount()
+        {
+                return referringObjects.size();
+        }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/StringGoldChecker.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2008, 2018, 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.
+ */
+package nsk.share;
+
+public class StringGoldChecker extends AbstractGoldChecker {
+
+    private final String goldenString;
+
+    public StringGoldChecker(String goldenString) {
+        this.goldenString = goldenString;
+    }
+
+    @Override
+    protected String getGoldenString() {
+        return goldenString;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/TestBug.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2001, 2018, 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.
+ */
+
+package nsk.share;
+
+/**
+ * Thrown when it becomes obvious that the test algorithm
+ * works incorrectly (for example - tries to write to debugee's
+ * stdin after it is already redirected, or something of the
+ * kind).
+ */
+public class TestBug extends Failure {
+        /** Explain particular failure. */
+        public TestBug(String message) {
+                super(message);
+        }
+
+        /** Enwrap another throwable. */
+        public TestBug(Throwable throwable) {
+                super(throwable);
+        }
+
+        public TestBug(String message, Throwable throwable) {
+                super(message, throwable);
+        }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/TestFailure.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2005, 2018, 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.
+ */
+package nsk.share;
+
+public class TestFailure extends RuntimeException {
+    public TestFailure() {
+        super();
+    }
+
+    public TestFailure(String message) {
+        super(message);
+    }
+
+    public TestFailure(String message, Throwable e) {
+        super(message, e);
+    }
+
+    public TestFailure(Throwable e) {
+        super(e);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/TestJNIError.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2006, 2018, 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.
+ */
+package nsk.share;
+
+public class TestJNIError
+        extends Error
+{
+        public TestJNIError(String message)
+        {
+                super(message);
+        }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/TimeoutHandler.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2001, 2018, 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.
+ */
+
+package nsk.share;
+
+import java.io.*;
+
+/**
+ * This class can be used to set timeout for test execution.
+ */
+public class TimeoutHandler {
+
+    /**
+     * Test execution timeout in minutes.
+     */
+    private int waitTime;
+
+    /**
+     * Make new <code>TimeoutHandler</code> object for timeout value
+     * specified in command line arguments.
+     */
+    public TimeoutHandler(ArgumentParser argumentHandler) {
+        this.waitTime = argumentHandler.getWaitTime();
+    }
+
+    /**
+     * Perform test execution in separate thread and wait for
+     * thread finishes or timeout exceeds.
+     */
+    public void runTest(Thread testThread) {
+        long millisec = waitTime * 60 * 1000;
+        testThread.start();
+        try {
+            testThread.join(millisec);
+        } catch (InterruptedException ex) {
+            throw new Failure(ex);
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/TreeNodesDenotation.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,175 @@
+/*
+ * Copyright (c) 2002, 2018, 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.
+ */
+
+package nsk.share;
+
+import java.util.*;
+
+/**
+ * This denotation provides naming and indexing for nodes
+ * of a binary, or ternary, or <tt>n</tt>-ary tree.
+ *
+ * <p>Here, <tt>n</tt> would be the length of a symbols
+ * string used as an alphabeth for nodes naming. For a
+ * binary tree, <tt>n=2</tt>, and an aplhabeth could be
+ * the <tt>"LR"</tt> string. This implies the following
+ * naming for tree nodes:
+ * <pre>
+ *              (empty)
+ *             /       \
+ *            L         R
+ *          /   \     /   \
+ *         LL   LR   RL   RR
+ *        /  \ /  \ /  \ /  \
+ * </pre>
+ *
+ * <p>Anyway, the tree root node is named with the empty
+ * string <tt>""</tt> and is indexed with 2-zeroes array
+ * <tt>{0,0}</tt>.
+ *
+ * <p>Index for a tree node is 2-elements <tt>int[]</tt>
+ * array. The 1st element is the node's level in a tree.
+ * The 2nd element is the item's number among all nodes of
+ * that level; provided that node items are enumerated from
+ * <tt>0</tt> to <tt>n</tt><sup>level</sup><tt>-1</tt>.
+ * Given a level, lexicographic order is assumed for the
+ * nodes of the same level.
+ *
+ * <p>For example: given the above sample tree, the node
+ * <tt>"L"</tt> has the index <tt>{1,0}</tt>, while the
+ * node <tt>"RL"</tt> has the index <tt>{2,2}</tt>.
+ *
+ * <p>In general case, ordering of characters used for nodes
+ * naming is implied by the given alphabeth. This may differ
+ * from the ``natural'' ordering. For example, if alphabeth
+ * is <tt>"ZYX...CBA"</tt>, then ordering for nodes would be
+ * opposite to ``natural''.
+ */
+public class TreeNodesDenotation extends Denotation {
+    /**
+     * Symbols to denote tree nodes.
+     *
+     * @see #TreeNodeDenotation(String)
+     */
+    private String alphabeth;
+
+    /**
+     * Standard denotation for a binary tree; alphabeth
+     * is <tt>"LR"</tt>.
+     *
+     * @see #TreeNodesDenotation(String)
+     */
+    public TreeNodesDenotation() {
+        this("LR");
+    }
+
+    /**
+     * Denotation for nodes of a tree.
+     *
+     * <p>Each tree node is marked with a string of symbols
+     * from the given <tt>alphabeth</tt>. A string length
+     * equals to the node's level. The root node is always
+     * denoted with the empty string.
+     *
+     * <p>For example, an <tt>alphabeth</tt> for a binary
+     * tree could be <tt>"LR"</tt>, or <tt>"01"</tt>, or
+     * any 2-symbols string. However, <tt>"lL"</tt> or
+     * <tt>"rR"</tt> would be illegal because of collision
+     * between upper- and lower- case letters.
+     *
+     * <p>In general case, it is illegal for <tt>alphabeth</tt>
+     * to contain two or several copies of the same symbol.
+     * This constructor deems lower- and upper-case variants
+     * of the same letter are the same symbol.
+     *
+     * @throws IllegalArgumentException If the <tt>alphabeth</tt>
+     * looks illegal.
+     */
+    public TreeNodesDenotation(String alphabeth) {
+        if (alphabeth.length() == 0)
+            throw new IllegalArgumentException("empty alphabeth");
+        // Check for lower- to upper- case collision:
+        this.alphabeth = alphabeth.toUpperCase();
+        int length = this.alphabeth.length();
+        Set<Character> pool = new HashSet<Character>(); // still empty
+        for (int i=0; i<length; i++)
+            pool.add(new Character(this.alphabeth.charAt(i)));
+        if (pool.size() != length)
+            throw new IllegalArgumentException("collision: " + alphabeth);
+    }
+
+    /**
+     * Check if the <tt>name</tt> is legal, and return the
+     * numeric index for the tree node denoted by the given
+     * <tt>name</tt>.
+     *
+     * @throws IllegalArgumentException If the <tt>name</tt>
+     * is illegal.
+     */
+    public int[] indexFor(String name) {
+        int level = name.length();
+        int factor = alphabeth.length();
+        long item = 0;
+        for (int i=0; i<level; i++) {
+            char symbol = Character.toUpperCase(name.charAt(i));
+            int position = alphabeth.indexOf(symbol);
+            if (position < 0)
+                throw new IllegalArgumentException("unknown symbol: " + name);
+            item = item*factor + position;
+            if (item < 0 || item > Integer.MAX_VALUE)
+                throw new IllegalArgumentException("too long name: " + name);
+        };
+        int[] index = new int [] { level, (int)item };
+        return index;
+    }
+
+    /**
+     * Check if the <tt>index[]</tt> is legal, and return
+     * a symbolic name for the tree node denoted by the
+     * given <tt>index[]</tt>.
+     *
+     * @throws IllegalArgumentException If the <tt>index[]</tt>
+     * is illegal.
+     */
+    public String nameFor(int[] index) {
+        if (index.length != 2)
+            throw new IllegalArgumentException(
+                "index dimention: " + index.length);
+        StringBuffer name = new StringBuffer(); // still empty
+        int level = index[0];
+        int item  = index[1];
+        if (level < 0 || item < 0)
+            throw new IllegalArgumentException(
+                "negative index: " + level + ", " + item);
+        int factor = alphabeth.length();
+        for (int i=0; i<level; i++) {
+            int k = item % factor;
+            name.append(alphabeth.charAt(k));
+            item = item / factor;
+        };
+        if (item != 0)
+            throw new IllegalArgumentException(
+                "out of range: {"+ index[0] + "," + index[1] + "}");
+        return new String(name.reverse());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/Wicket.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,229 @@
+/*
+ * Copyright (c) 2003, 2018, 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.
+ */
+
+package nsk.share;
+
+import java.io.PrintStream;
+
+/**
+ * Wicket provides a means for one or more threads to suspend execution
+ * (to wait) until notified by one or more other threads that some set
+ * of locks is now open.
+ *
+ * <p>Wicket instances are intended to be used generally in the following
+ * scenarios:
+ *
+ *   <ul><li>One thread starts one or more child threads and waits until the
+ *   child threads to be started.
+ *
+ *   <li>One thread starts one or more child threads and waits until at least
+ *   one of the child threads to be started.
+ *
+ *   <li>One or more child threads wait until a main thread lets them
+ *   to finish.
+ *
+ *   <li>Disable the current thread for thread scheduling purposes, for up to
+ *   the specified waiting time.</ul>
+ */
+
+public class Wicket {
+
+    /** Number of closed locks, can be greater or equal to zero */
+    private int count;
+
+    /** Number of waiters **/
+    private int waiters = 0;
+
+    /** Enable debug output */
+    private PrintStream debugOutput = null;
+
+    /** Wicket's string identifier */
+    private String name = "";
+
+    /**
+     * Construct a Wicket with only one closed lock.
+     */
+    public Wicket() {
+        this(1);
+    }
+
+    /**
+     * Construct a Wicket with the given number of closed locks.
+     *
+     * @param _name Wicket's identifier
+     * @param _count the initial number of closed locks
+     * @param _debugOutput whether to print debug info or not
+     * @throws IllegalArgumentException if count is less than 1
+     */
+    public Wicket(String _name, int _count, PrintStream _debugOutput) {
+        this(_count);
+        name = _name;
+        debugOutput = _debugOutput;
+    }
+
+    /**
+     * Construct a Wicket with the given number of closed locks.
+     *
+     * @param count the initial number of closed locks
+     * @throws IllegalArgumentException if count is less than 1
+     */
+    public Wicket(int count) {
+        if (count < 1)
+            throw new IllegalArgumentException(
+                "count is less than one: " + count);
+        this.count = count;
+    }
+
+    /**
+     * Wait for all locks of this Wicket to be open.
+     *
+     * <p>If all locks are already open then returns immediately.
+     *
+     * <p>If at least one lock is still closed then the current thread becomes
+     * disabled for thread scheduling purposes and lies dormant until all
+     * the locks will be open by some other threads. One lock can be open
+     * by invoking the unlock method for this Wicket.
+     *
+     * <p>Please note, that the method would ignore Thread.interrupt() requests.
+     */
+    public synchronized void waitFor() {
+        ++waiters;
+        if (debugOutput != null) {
+            debugOutput.printf("Wicket %s: waitFor()\n", name);
+        }
+
+        while (count > 0) {
+            try {
+                wait();
+            } catch (InterruptedException e) {}
+        }
+        --waiters;
+    }
+
+    /**
+     * Wait for all locks of this Wicket to be open within the given
+     * period of time.
+     *
+     * <p>If all locks are already open then returns immediately with zero.
+     *
+     * <p>If the time is equal to zero, the method will not
+     * wait and returns a number of closed locks,
+     * if all locks are open, the return value is zero.
+     *
+     * <p>If at least one lock is still closed then the current thread becomes
+     * disabled for thread scheduling purposes and lies dormant until
+     * of the two things happens:
+     *
+     *   <ul><li>Some other threads invoke the unlock method for this Wicket
+     *   to open all the closed locks; or
+     *
+     *   <li>The specified waiting time elapses.</ul>
+     *
+     * <p>If all locks are open then the return value is 0.
+     *
+     * <p>If the specified waiting time elapses and some locks are still closed
+     * then the return value is equal to number of closed locks.
+     *
+     * <p>Please note, that the method would ignore Thread.interrupt() requests.
+     *
+     * @param timeout the maximum time to wait in milliseconds
+     * @return the number of closed locks
+     * @throws IllegalArgumentException if timeout is less than 0
+     */
+    public synchronized int waitFor(long timeout) {
+        if (debugOutput != null) {
+            debugOutput.printf("Wicket %s: waitFor(%d)\n", name, timeout);
+        }
+
+        if (timeout < 0)
+            throw new IllegalArgumentException(
+                "timeout value is negative: " + timeout);
+        ++waiters;
+        long waitTime = timeout;
+        long startTime = System.currentTimeMillis();
+        while (count > 0 && waitTime > 0) {
+            try {
+                wait(waitTime);
+            } catch (InterruptedException e) {}
+            waitTime = timeout - (System.currentTimeMillis() - startTime);
+        }
+        --waiters;
+        return (count);
+    }
+
+    /**
+     * Unlock one closed lock.
+     *
+     * <p>Open a lock, reducing the number of closed locks by one.
+     *
+     * <p>If last closed lock is opened then all of the threads waiting
+     * by invoking the waitFor method for this Wicket will be released
+     * and re-enabled for thread scheduling purposes.
+     *
+     * @throws IllegalStateException if there is no one closed lock
+     */
+    public synchronized void unlock() {
+        if (debugOutput != null) {
+            debugOutput.printf("Wicket %s: unlock()\n", name);
+        }
+
+        if (count == 0)
+            throw new IllegalStateException("locks are already open");
+
+        --count;
+        if (count == 0) {
+            notifyAll();
+        }
+    }
+
+    /**
+     * Unlock all closed locks.
+     *
+     * <p>Open all closed locks, setting the number of closed locks to zero.
+     *
+     * <p>If any threads are waiting by invoking the waitFor method for
+     * this Wicket then they will be released and re-enabled for thread
+     * scheduling purposes.
+     */
+    public synchronized void unlockAll() {
+        if (debugOutput != null) {
+            debugOutput.printf("Wicket %s: unlockAll()\n", name);
+        }
+
+        count = 0;
+        notifyAll();
+    }
+
+    /**
+     * Return current number of waiters - threads that are currently
+     * waiting using one of waitFor methods.
+     *
+     * @return number of waiters
+     */
+    public synchronized int getWaiters() {
+        if (debugOutput != null) {
+            debugOutput.printf("Wicket %s: getWaiters()\n", name);
+        }
+        return waiters;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/AODRunnerArgParser.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2008, 2018, 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.
+ */
+package nsk.share.aod;
+
+import nsk.share.*;
+import java.util.*;
+
+public class AODRunnerArgParser extends ArgumentParser {
+
+    public static final String jarAgentParam = "ja";
+
+    public static final String nativeAgentParam = "na";
+
+    public static final String targetAppParam = "target";
+
+    public static final String javaOptsParam = "javaOpts";
+
+    public static final String testedJdkParam = "jdk";
+
+    private static List<String> supportedOptions;
+
+    static {
+        supportedOptions = new ArrayList<String>();
+        supportedOptions.add(jarAgentParam);
+        supportedOptions.add(nativeAgentParam);
+        supportedOptions.add(targetAppParam);
+        supportedOptions.add(javaOptsParam);
+        supportedOptions.add(testedJdkParam);
+    }
+
+    private List<AgentInformation> agents;
+
+    public AODRunnerArgParser(String[] args) {
+        super(args);
+    }
+
+    protected boolean checkOption(String option, String value) {
+        if (super.checkOption(option, value))
+            return true;
+
+        if (!supportedOptions.contains(option))
+            return false;
+
+        if (option.equals(jarAgentParam)) {
+            addAgentInfo(true, value);
+        }
+
+        if (option.equals(nativeAgentParam)) {
+            addAgentInfo(false, value);
+        }
+
+        return true;
+    }
+
+    protected void checkOptions() {
+        if (agents == null) {
+            agents = new ArrayList<AgentInformation>();
+        }
+    }
+
+    private void addAgentInfo(boolean jarAgent, String unsplittedAgentsString) {
+        if (agents == null) {
+            agents = new ArrayList<AgentInformation>();
+        }
+
+        String agentStrings[];
+
+        if (unsplittedAgentsString.contains(","))
+            agentStrings = unsplittedAgentsString.split(",");
+        else
+            agentStrings = new String[]{unsplittedAgentsString};
+
+        for (String agentString : agentStrings) {
+            int index = agentString.indexOf('=');
+
+            if (index > 0) {
+                String pathToAgent = agentString.substring(0, index);
+                String options = agentString.substring(index + 1);
+                agents.add(new AgentInformation(jarAgent, pathToAgent, options));
+            } else {
+                agents.add(new AgentInformation(jarAgent, agentString, null));
+            }
+        }
+    }
+
+    public String getTargetApp() {
+        if (!options.containsKey(targetAppParam))
+            throw new TestBug("Target application isn't specified");
+
+        return options.getProperty(targetAppParam);
+    }
+
+    public String getTestedJDK() {
+        if (!options.containsKey(testedJdkParam))
+            throw new TestBug("Tested JDK isn't specified");
+
+        return options.getProperty(testedJdkParam);
+    }
+
+    public String getJavaOpts() {
+        return options.getProperty(javaOptsParam, "");
+    }
+
+    public List<AgentInformation> getAgents() {
+        return agents;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/AODTargetArgParser.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2008, 2018, 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.
+ */
+package nsk.share.aod;
+
+import nsk.share.*;
+import java.util.*;
+
+public class AODTargetArgParser extends ArgumentParser {
+
+    public static final String agentsNumberParam = "agentsNumber";
+
+    public static final String socketPortParam = "port";
+
+    private int expectedAgentsNumber;
+
+    private int port;
+
+    private static List<String> supportedOptions;
+
+    static {
+        supportedOptions = new ArrayList<String>();
+        supportedOptions.add(agentsNumberParam);
+        supportedOptions.add(socketPortParam);
+    }
+
+    public AODTargetArgParser(String[] args) {
+        super(args);
+    }
+
+    protected boolean checkOption(String option, String value) {
+        if (super.checkOption(option, value))
+            return true;
+
+        if (!supportedOptions.contains(option))
+            return false;
+
+        if (option.equals(agentsNumberParam)) {
+            expectedAgentsNumber = Integer.parseInt(value);
+            if (expectedAgentsNumber < 0)
+                throw new TestBug("Invalid value of '" + option + "'");
+        } else if (option.equals(socketPortParam)) {
+            port = Integer.parseInt(value);
+            if (port <= 0 || port > 65535)
+                throw new TestBug("Invalid value of '" + option + "':" + port +" (it is expected to be in the range [1..65535]");
+        }
+
+        return true;
+    }
+
+    public int getExpectedAgentsNumber() {
+        if (!options.containsKey(agentsNumberParam))
+            throw new TestBug("Number of expected agents isn't specified");
+
+        return expectedAgentsNumber;
+    }
+
+    public int getPort() {
+        if (!options.containsKey(socketPortParam))
+            return -1;
+
+        return port;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/AODTestRunner.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,186 @@
+/*
+ * Copyright (c) 2008, 2018, 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.
+ */
+package nsk.share.aod;
+
+import java.io.*;
+import nsk.share.*;
+import nsk.share.jpda.SocketIOPipe;
+
+/*
+ Class AODTestRunner is part of the framework used in the AttachOnDemand tests
+ (tests against Attach API, API from package com.sun.tools.attach).
+
+ AODTestRunner is used as main class in AttachOnDemand tests, it performs following
+ actions:
+ - starts target application
+
+ - finds VM id for target VM (this id is needed for dynamic attach)
+
+ - by default AODTestRunner tries to attach specified via command line agents to target VM
+ (subclasses can override this default behavior)
+
+ - waits for target application completion
+
+Target application class, agents that should be attached, JDK used to run target application and
+VM options passed to target VM should be specified via command line.
+ */
+public class AODTestRunner {
+
+    public static final String targetAppIdProperty = "vmsqe.aod.targetAppId";
+    public static final String appIdProperty = "vmsqe.aod.AppId";
+
+    public static final long TARGET_APP_CONNECT_TIMEOUT = 5 * 60 * 1000; // 5 min
+
+    public static final long TARGET_APP_WORK_TIMEOUT = 30 * 60 * 1000; // 30 min (standard VM testbase test timeout)
+
+    protected Log log;
+
+    protected SocketIOPipe pipe;
+
+    protected ProcessExecutor targetAppExecutor;
+
+    // target application ready for attach
+    public static final String SIGNAL_READY_FOR_ATTACH = "ready";
+
+    // target application may finish execution
+    public static final String SIGNAL_FINISH = "finish";
+
+    protected AODRunnerArgParser argParser;
+
+    protected AODTestRunner(String[] args) {
+        log = new Log(System.out, true);
+
+        argParser = createArgParser(args);
+    }
+
+    /*
+     * This method is introduced to let subclasses to create its own parsers
+     */
+    protected AODRunnerArgParser createArgParser(String[] args) {
+        return new AODRunnerArgParser(args);
+    }
+
+    protected void doTestActions(String targetVMId) throws Throwable {
+        AgentsAttacher attacher = new AgentsAttacher(targetVMId, argParser.getAgents(), log);
+        attacher.attachAgents();
+    }
+
+    protected String getCurrentVMId() {
+        String currentVMId = "" + ProcessHandle.current().pid();
+        log.display("Current VM id was identified: " + currentVMId);
+
+        return currentVMId;
+    }
+
+    protected void runTest() {
+
+        try {
+            String targetAppId = System.getProperty(targetAppIdProperty);
+            if(targetAppId == null || targetAppId.isEmpty()) {
+                // use PID as default appID
+                targetAppId = "" + ProcessHandle.current().pid();
+            }
+            /*
+             * Create target application id required by the Utils.findVMIdUsingJPS
+             */
+            String targetAppCmd =
+                    // path to java
+                    argParser.getTestedJDK() + File.separator + "bin" + File.separator + "java " +
+                            // VM property to identify VM running target application
+                            "-D" + appIdProperty + "=" + targetAppId +  " " +
+                            // VM opts
+                            argParser.getJavaOpts() + " -XX:+EnableDynamicAgentLoading " +
+                            // target application class
+                            argParser.getTargetApp() + " " +
+                            // additional target application parameter - number of
+                            // agents that will be attached
+                            "-" + AODTargetArgParser.agentsNumberParam + " " + argParser.getAgents().size();
+
+            pipe = SocketIOPipe.createServerIOPipe(log, 0, TARGET_APP_CONNECT_TIMEOUT);
+            targetAppCmd += " -" + AODTargetArgParser.socketPortParam + " " + pipe.getPort();
+
+            log.display("Starting target application: " + targetAppCmd);
+            targetAppExecutor = new ProcessExecutor(targetAppCmd, TARGET_APP_WORK_TIMEOUT, "TargetApp");
+            targetAppExecutor.startProcess();
+
+            /*
+             * Don't try to attach agents until target application isn't initialized
+             */
+            String signal = pipe.readln();
+            log.display("Signal received: '" + signal + "'");
+            if ((signal == null) || !signal.equals(SIGNAL_READY_FOR_ATTACH))
+                throw new TestBug("Unexpected TargetApplication signal: '" + signal + "'");
+
+            String targetVMId = Long.toString(targetAppExecutor.pid());
+            log.display("Target VM id was identified: " + targetVMId);
+
+            doTestActions(targetVMId);
+
+            /*
+             * When test actions finished let target application finish execution
+             */
+            log.display("Sending signal: '" + SIGNAL_FINISH + "'");
+            pipe.println(SIGNAL_FINISH);
+
+            targetAppExecutor.waitForProcess();
+
+            File file = new File(targetAppId);
+            if (file.exists()) {
+                file.deleteOnExit();
+            }
+
+            if (targetAppExecutor.getExitCode() != 0) {
+                throw new Failure("Target application finished with non-zero code " + targetAppExecutor.getExitCode());
+            }
+
+            postTargetExitHook();
+
+        } catch (Failure f) {
+            throw f;
+        } catch (Throwable t) {
+            throw new Failure("Unexpected exception during test execution: " + t, t);
+        } finally {
+            if (pipe != null) {
+                pipe.close();
+            }
+            if (targetAppExecutor != null) {
+                targetAppExecutor.destroyProcess();
+            }
+        }
+    }
+
+    /*
+     * Allow users of this class to specify actions to be taken after the target exits
+     */
+    protected void postTargetExitHook() {
+        // do nothing by default
+    }
+
+    public static String createApplicationId() {
+        return new Long(System.currentTimeMillis()).toString();
+    }
+
+    public static void main(String[] args) {
+        new AODTestRunner(args).runTest();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/AbstractJarAgent.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,257 @@
+/*
+ * Copyright (c) 2008, 2018, 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.
+ */
+package nsk.share.aod;
+
+import java.lang.instrument.*;
+import java.io.*;
+import nsk.share.*;
+
+/*
+
+AbstractJarAgent is base class for java agents used in AttachOnDemand tests
+(tests against Attach API, API from package com.sun.tools.attach).
+
+In all AttachOnDemand tests the same algorithm is used:
+    - java application where agent is loaded to (target application) based on
+     class nsk.share.aod.TargetApplicationWaitingAgents starts and waits when
+     test agents will be loaded
+
+    - special application (nsk.share.jvmti.aod.AgentsAttacher) loads test agents
+    in the target application using Attach API
+
+    - when agent is loaded it notifies target application about that and executes
+    test-specific actions. When agent execution is completed it also notifies
+    target application about that
+
+    - when all test agents finish execution target application checks its status
+    (passed or failed) and also finishes
+
+Each java agent should have method 'agentmain' where only agent initialization should be done,
+main agent's actions should be executed in special thread started from 'agentmain'.
+Class AbstractJarAgent incapsulates actions common for all java agents: agent initialization,
+starting thread executing agent's actions and communication with target application.
+
+In most cases test agents should override only method 'agentActions' and its 'agentmain'
+should contain only call of the method 'AbstractJarAgent.runJarAgent'.
+
+Typical agent class looks like this:
+
+public class agentExample extends AbstractJarAgent {
+
+    protected void init(String[] args) {
+        // parse agent's options and do test-specific initialization
+    }
+
+    protected void agentActions() {
+        // do test specific actions
+    }
+
+    public static void agentmain(final String options, Instrumentation inst) {
+        new agentExample().runJarAgent(options, inst);
+    }
+}
+ */
+abstract public class AbstractJarAgent {
+
+    private boolean finishedSuccessfully = true;
+
+    private Log log;
+
+    protected void display(String message) {
+        log.display(outputPrefix + message);
+    }
+
+    protected void complain(String message) {
+        log.complain(outputPrefix + message);
+    }
+
+    protected void logThrowable(Throwable t) {
+        t.printStackTrace(log.getOutStream());
+    }
+
+    /*
+     * Instrumentation object passed to the 'agentmain' method
+     */
+    protected Instrumentation inst;
+
+    private String name;
+
+    private String outputPrefix;
+
+    private String pathToNewByteCode;
+
+    protected String pathToNewByteCode() {
+        return pathToNewByteCode;
+    }
+
+    /*
+     * Subclasses should report about test failures using this method
+     */
+    protected void setStatusFailed(String errorMessage) {
+        finishedSuccessfully = false;
+        complain("ERROR: " + errorMessage);
+    }
+
+    /*
+     * Initialization method, called from agentmain before method agentActions is called
+     * (it introduced for overriding in subclasses)
+     */
+    protected void init(String[] args) {
+    }
+
+    protected static class AgentOption {
+        public String name;
+        public String value;
+        public AgentOption(String name, String value) {
+            this.name = name;
+            this.value = value;
+        }
+    }
+
+    protected AgentOption parseAgentArgument(String arg) {
+        int index = arg.indexOf('=');
+        if (index <= 0) {
+            throw new TestBug("Invalid agent parameters format");
+        }
+        return new AgentOption(arg.substring(0, index), arg.substring(index + 1));
+    }
+
+    static protected final String agentNameOption = "-agentName";
+
+    static protected final String pathToNewByteCodeOption = "-pathToNewByteCode";
+
+    /*
+     * Parse agent's options, initialize common parameters
+     */
+    private void defaultInit(String[] args) {
+        for (int i = 0; i < args.length; i++) {
+            AgentOption option = parseAgentArgument(args[i]);
+            if (option.name.equals(agentNameOption)) {
+                name = option.value;
+                outputPrefix = name + ": ";
+            } else if (option.name.equals(pathToNewByteCodeOption)) {
+                pathToNewByteCode = option.value;
+            }
+        }
+
+        if (name == null)
+            throw new TestBug("Agent name wasn't specified");
+
+        log = new Log(System.out, true);
+    }
+
+    /*
+     * Special thread which is started from agentmain method and executing main
+     * agent's actions. When agent completes execution AgentThread notifies
+     * target application about that.
+     */
+    class AgentThread extends Thread {
+
+        AgentThread() {
+            super("Jar agent thread (agent: " + name + ")");
+        }
+
+        public void run() {
+            try {
+                agentActions();
+            } catch (Throwable t) {
+                setStatusFailed("Unexpected exception in the JarAgent: " + t);
+                logThrowable(t);
+            } finally {
+                TargetApplicationWaitingAgents.agentFinished(name, finishedSuccessfully);
+            }
+        }
+    }
+
+    /*
+     * This methods parses agent's options, initializes agent, notifies target application
+     * that agent is started and starts thread executing main agent's actions.
+     * Agents used in AttachOnDemand tests should call this method from its agentmain methods.
+     */
+    public final void runJarAgent(String options, Instrumentation inst) {
+        if (options == null)
+            throw new TestBug("Agent options weren't specified");
+
+        this.inst = inst;
+
+        String[] args = options.split(" ");
+
+        // initialize common parameters
+        defaultInit(args);
+
+        // test-specific initialization
+        init(args);
+
+        // notify target application that agent was loaded and initialized
+        TargetApplicationWaitingAgents.agentLoaded(name);
+
+        // start special thread executing test-specific actions
+        new AgentThread().start();
+    }
+
+    /*
+     * Actions specific for test should be realized in this method.
+     * This method is called from special thread started from agentmain method
+     * after agent initialization
+     */
+    abstract protected void agentActions() throws Throwable;
+
+
+    /*
+     * Create ClassDefinition object for given class, path to the new class file
+     * is specified in the parameter 'pathToByteCode'
+     */
+    protected static ClassDefinition createClassDefinition(Class<?> klass,
+            String pathToByteCode) throws IOException {
+        File classFile = new File(pathToByteCode + File.separator +
+                klass.getName().replace(".", File.separator) +
+                ".class");
+
+        if (classFile.length() > Integer.MAX_VALUE)
+            throw new Failure("Class file '" + classFile.getName() + " 'too large");
+
+        byte data[] = new byte[(int)classFile.length()];
+
+        DataInputStream in = null;
+        try {
+            in = new DataInputStream(new FileInputStream(classFile));
+            in.readFully(data);
+        } finally {
+            if (in != null)
+                in.close();
+        }
+
+        return new ClassDefinition(klass, data);
+    }
+
+    /*
+     * Redefine given class using path to byte code specified with options -pathToNewByteCode
+     */
+    protected void redefineClass(Class<?> klass) throws Throwable {
+        if (pathToNewByteCode() == null)
+            throw new TestBug("Path to new class files wasn't specified");
+
+        ClassDefinition newClassDef = createClassDefinition(klass, pathToNewByteCode());
+        inst.redefineClasses(newClassDef);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/AgentInformation.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2008, 2018, 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.
+ */
+package nsk.share.aod;
+
+/*
+ * Class contains information about dynamically attached agent
+ */
+public class AgentInformation {
+
+    // counters used for unique agent names generation
+
+    private static int jarAgentsCounter;
+
+    private static int nativeAgentsCounter;
+
+    public boolean jarAgent;
+
+    public String pathToAgent;
+
+    public String agentOptions;
+
+    public AgentInformation(boolean jarAgent, String pathToAgent, String options, boolean addAgentNameOption) {
+        this.jarAgent = jarAgent;
+        this.pathToAgent = pathToAgent;
+        this.agentOptions = options;
+
+        // add to agent options additional parameter - agent name (it used by nsk.share.aod framework)
+
+        String name;
+
+        if (jarAgent)
+            name = "JarAgent-" + jarAgentsCounter++;
+        else
+            name = "NativeAgent-" + nativeAgentsCounter++;
+
+        if (addAgentNameOption) {
+            if (this.agentOptions == null) {
+                this.agentOptions = "-agentName=" + name;
+            } else {
+                this.agentOptions += " -agentName=" + name;
+            }
+        }
+    }
+
+    public AgentInformation(boolean jarAgent, String pathToAgent, String options) {
+        this(jarAgent, pathToAgent, options, true);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/AgentsAttacher.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2008, 2018, 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.
+ */
+package nsk.share.aod;
+
+import nsk.share.*;
+import java.io.IOException;
+import java.util.*;
+import com.sun.tools.attach.*;
+
+/*
+ * This class loads java and native agents in the running VM using Attach API
+ * (API from package com.sun.tools.attach).
+ */
+public class AgentsAttacher {
+
+    protected String targetVMId;
+
+    protected List<AgentInformation> agents;
+
+    protected Log log;
+
+    public AgentsAttacher(String targetVMId, List<AgentInformation> agents, Log log) {
+        this.targetVMId = targetVMId;
+        this.agents = agents;
+        this.log = log;
+    }
+
+    public void attachAgents() {
+        VirtualMachine vm = null;
+
+        try {
+            log.display("Trying to get VirtualMachine object");
+            vm = VirtualMachine.attach(targetVMId);
+        } catch (AttachNotSupportedException e) {
+            log.complain("Unexpected AttachNotSupportedException during VirtualMachine.attach: " + e);
+            e.printStackTrace(log.getOutStream());
+        } catch (IOException e) {
+            log.complain("Unexpected IOException during VirtualMachine.attach: " + e);
+            e.printStackTrace(log.getOutStream());
+        }
+
+        if (vm == null) {
+            failed("Unable to create VirtualMachine object");
+        }
+
+        log.display("VirtualMachine was created: " + vm);
+
+        try {
+            for (AgentInformation agentInfo : agents) {
+                tryToLoadAgent(vm, agentInfo.pathToAgent, agentInfo.agentOptions, agentInfo.jarAgent);
+            }
+        } finally {
+            try {
+                log.display("Detaching from the VM '" + vm + "'");
+                vm.detach();
+            } catch (IOException e) {
+                failed("Unexpected IOException during detaching: " + e, e);
+            }
+        }
+    }
+
+    protected void tryToLoadAgent(VirtualMachine vm, String agent, String agentOptions, boolean jarAgent) {
+        boolean agentLoaded = false;
+
+        Throwable failureCause = null;
+
+        try {
+            if (jarAgent) {
+                log.display("Trying to load jar agent: '" + agent + "' (agent options: '" + agentOptions + "')");
+                vm.loadAgent(agent, agentOptions);
+            } else {
+                log.display("Trying to load native agent: '" + agent + "' (agent options: '" + agentOptions + "')");
+                vm.loadAgentLibrary(agent, agentOptions);
+            }
+            log.display("Agent was loaded");
+            agentLoaded = true;
+        } catch (AgentLoadException e) {
+            failureCause = e;
+            log.complain("Unexpected AgentLoadException during agent loading: " + e);
+            if (jarAgent) {
+                log.complain("(probably the agent does not exist, or cannot be started in the manner specified in "
+                        + "the java.lang.instrument specification)");
+            } else {
+                log.complain("(probably agent library does not exist, or cannot be loaded for another reason)");
+            }
+            e.printStackTrace(log.getOutStream());
+        } catch (AgentInitializationException e) {
+            failureCause = e;
+            log.complain("Unexpected AgentInitializationException during agent loading: " + e);
+            if (jarAgent) {
+                log.complain("(agentmain have thrown an exception)");
+            } else {
+                log.complain("Agent_OnAttach function returned an error: " + e.returnValue());
+            }
+            e.printStackTrace(log.getOutStream());
+        } catch (IOException e) {
+            failureCause = e;
+            log.complain("Unexpected IOException during agent loading: " + e);
+            e.printStackTrace(log.getOutStream());
+        }
+
+        if (!agentLoaded) {
+            if (failureCause != null)
+                failed("Couldn't attach agent to the target application", failureCause);
+            else
+                failed("Couldn't attach agent to the target application");
+        }
+    }
+
+    private void failed(String errorMessage) {
+        throw new Failure(errorMessage);
+    }
+
+    private void failed(String errorMessage, Throwable t) {
+        throw new Failure(errorMessage, t);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/DummyTargetApplication.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2008, 2018, 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.
+ */
+package nsk.share.aod;
+
+import nsk.share.*;
+import nsk.share.jpda.SocketIOPipe;
+
+/*
+Class TargetApplication is part of the framework used in the AttachOnDemand tests
+(tests against Attach API, API from package com.sun.tools.attach).
+
+This class is used in tests where main test application uses Attach API, but doesn't load agents to the another VM.
+In these test there are 2 java applications: main application using Attach API and another
+'dummy' application which should be alive while main application is working.
+
+To synchronize main and dummy application SocketIOPipe is used: when DummyTargetApplication starts
+it sends signal that it is ready for test and waits for signal permitting finish execution
+(socket number used for connection establishing should be passed via command line).
+ */
+public class DummyTargetApplication {
+
+    protected Log log = new Log(System.out, true);
+
+    protected AODTargetArgParser argParser;
+
+    protected SocketIOPipe pipe;
+
+    public DummyTargetApplication(String[] args) {
+        argParser = new AODTargetArgParser(args);
+    }
+
+    protected void targetApplicationActions() {
+        // do nothing by default
+    }
+
+    public void runTargetApplication() {
+        pipe = SocketIOPipe.createClientIOPipe(log, "localhost", argParser.getPort(), 0);
+        log.display("Sending signal '" + AODTestRunner.SIGNAL_READY_FOR_ATTACH + "'");
+        pipe.println(AODTestRunner.SIGNAL_READY_FOR_ATTACH);
+
+        targetApplicationActions();
+
+        String signal = pipe.readln();
+        log.display("Signal received: '" + signal + "'");
+
+        if ((signal == null) || !signal.equals(AODTestRunner.SIGNAL_FINISH))
+            throw new TestBug("Unexpected signal: '" + signal + "'");
+    }
+
+    public static void main(String[] args) {
+        new DummyTargetApplication(args).runTargetApplication();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/ProcessExecutor.java	Mon Apr 30 18:10:24 2018 -0700
@@ -0,0 +1,251 @@
+/*
+ * Copyright (c) 2008, 2018, 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.
+ */
+package nsk.share.aod;
+
+import java.io.*;
+import java.util.*;
+import nsk.share.*;
+
+public class ProcessExecutor {
+
+    private String[] cmdLine;
+
+    private long timeout;
+
+    private boolean printProcessOutput;
+
+    private String processOutputPrefix;
+
+    private InputStreamReaderThread outReader;
+
+    private InputStreamReaderThread errReader;
+
+    private Process startedProcess;
+
+    private ProcessWaiterThread processWaiter;
+
+    private long expectedFinishTime;
+
+    private volatile boolean executionCompleted;
+
+    private int exitCode;
+
+    private class InputStreamReaderThread extends Thread {
+        private BufferedReader in;
+
+        private String outputPrefix;
+
+        private List<String> output = new ArrayList<String>();
+
+        private volatile boolean streamWasAbruptlyClosed;
+
+        private Throwable unexpectedException;
+
+        public InputStreamReaderThread(InputStream in, String prefix) {
+            this.in = new BufferedReader(new InputStreamReader(in));
+            this.outputPrefix = prefix;
+            setDaemon(true);
+        }
+
+        public void streamWasAbruptlyClosed(boolean newValue) {
+            streamWasAbruptlyClosed = newValue;
+        }
+
+        public void run() {
+            try {
+                while (true) {
+                    String line = in.readLine();
+                    if (line == null)
+                        return;
+
+                    output.add(line);
+
+                    if (printProcessOutput)
+                        System.out.println(outputPrefix + line);
+                }
+            } catch (IOException e) {
+                if (!streamWasAbruptlyClosed) {
+                    unexpectedException = e;
+                    e.printStackTrace( );
+                }
+            } catch (Throwable t) {
+                unexpectedException = t;
+                t.printStackTrace( );
+            }
+        }
+
+        void checkStatus() {
+            if (unexpectedException != null)
+                throw new Failure("Exception was thrown during InputStreamReaderThread work: " + unexpectedException,
+                        unexpectedException);
+        }
+    }
+
+    private class ProcessWaiterThread extends Thread {
+
+        private Throwable unexpectedException;
+
+        private Process process;
+
+        private InputStreamReaderThread outReader;
+
+        private InputStreamReaderThread errReader;
+
+        ProcessWaiterThread(Process process, InputStreamReaderThread outReader, InputStreamReaderThread errReader) {
+            this.process = process;
+            this.outReader = outReader;
+            this.errReader = errReader;
+
+            setDaemon(true);
+        }
+
+        public void run() {
+            try {
+                exitCode = process.waitFor();
+                outReader.join();
+                errReader.join();
+
+                synchronized (ProcessWaiterThread.this) {
+                    executionCompleted = true;
+                    ProcessWaiterThread.this.notify();
+                }
+            } catch (InterruptedException e) {
+                /*
+                 * ProcessWaiterThread is interrupted if started process
+                 * didn't finish in expected time
+                 */
+            } catch (Throwable t) {
+                unexpectedException = t;
+                t.printStackTrace();
+            }
+        }
+
+        void checkStatus() {
+            if (unexpectedException != null)
+                throw new Failure("Exception was thrown during ProcessWaiterThread work: "
+