blob: 4aabd5f2895a18236e352c9aea5cb53a6a6ca043 [file] [log] [blame]
Alex Lightfc81d802018-12-07 13:39:05 -08001/*
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
17import java.lang.reflect.Method;
18import java.util.ArrayList;
19import java.util.Base64;
20import java.util.LinkedList;
21import java.lang.reflect.Executable;
22
23import art.*;
24
25public class Main {
26 /**
27 * NB This test cannot be run on the RI.
28 * TODO We should make this run on the RI.
29 */
30
31 public static void main(String[] args) throws Exception {
32 doTest();
33 }
34
35 public static volatile boolean started = false;
36
37 public static void doNothing() {}
38 public static void notifyBreakpointReached(Thread thr, Executable e, long l) {}
39
40 public static void doTest() throws Exception {
41 final Object lock = new Object();
Orion Hodson26ab2702020-07-29 09:54:10 +010042 Breakpoint.Manager manager = new Breakpoint.Manager();
Alex Lightfc81d802018-12-07 13:39:05 -080043 Breakpoint.startBreakpointWatch(
44 Main.class,
45 Main.class.getDeclaredMethod("notifyBreakpointReached", Thread.class, Executable.class, Long.TYPE),
46 null);
47 Thread thr = new Thread(() -> {
48 synchronized (lock) {
49 started = true;
50 // Wait basically forever.
51 try {
52 lock.wait(Integer.MAX_VALUE - 1);
53 } catch (Exception e) {
54 throw new Error("WAIT EXCEPTION", e);
55 }
56 }
57 });
58 // set the breakpoint.
Orion Hodson26ab2702020-07-29 09:54:10 +010059 manager.setBreakpoint(Main.class.getDeclaredMethod("doNothing"), 0l);
Alex Lightfc81d802018-12-07 13:39:05 -080060 thr.start();
61 while (!started || thr.getState() != Thread.State.TIMED_WAITING);
62 // Redefine while thread is paused.
63 forceRedefine(Object.class, Thread.currentThread());
64 // Clear breakpoints.
Orion Hodson26ab2702020-07-29 09:54:10 +010065 manager.clearAllBreakpoints();
Alex Lightfc81d802018-12-07 13:39:05 -080066 // set the breakpoint again.
Orion Hodson26ab2702020-07-29 09:54:10 +010067 manager.setBreakpoint(Main.class.getDeclaredMethod("doNothing"), 0l);
Alex Lightfc81d802018-12-07 13:39:05 -080068 // Wakeup
69 synchronized(lock) {
70 lock.notifyAll();
71 }
72 thr.join();
73 }
74
75 private static native void forceRedefine(Class c, Thread thr);
76}