1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package art; 18 19 public class Test1943 { run()20 public static void run() throws Exception { 21 final Thread target_thread = new Thread(() -> { 22 nativeRun(); 23 }, "target_thread"); 24 25 target_thread.start(); 26 27 // wait for the other thread to spin holding lock. 28 waitForPause(); 29 30 // Ensure that the other thread is in a wait. 31 grabRawMonitor(); 32 System.out.println("target_thread is sleeping in a wait."); 33 34 // Suspend it from java. 35 System.out.println("Suspend target_thread."); 36 Suspension.suspend(target_thread); 37 38 // Let it try to unlock the monitor. 39 System.out.println("Wake up the target_thread."); 40 // Let the thread try to lock the monitor. 41 nativeNotify(); 42 43 // Ensure that the other thread is suspended without the monitor. 44 grabRawMonitor(); 45 System.out.println("target_thread is sleeping in suspend without lock."); 46 47 // Check other thread is still alive 48 System.out.println("target_thread.isAlive() = " + target_thread.isAlive()); 49 50 // Resume it from java 51 System.out.println("resumed target_thread"); 52 Suspension.resume(target_thread); 53 54 // Make sure the monitor is gone. 55 grabRawMonitor(); 56 System.out.println("target_thread doesn't hold lock!"); 57 58 target_thread.join(); 59 } 60 nativeRun()61 public static native void nativeRun(); waitForPause()62 public static native void waitForPause(); nativeNotify()63 public static native void nativeNotify(); 64 // Gets then releases raw monitor. grabRawMonitor()65 public static native void grabRawMonitor(); 66 } 67