|
| 1 | +/* |
| 2 | + * Copyright IBM Corp. and others 2024 |
| 3 | + * |
| 4 | + * This program and the accompanying materials are made available under |
| 5 | + * the terms of the Eclipse Public License 2.0 which accompanies this |
| 6 | + * distribution and is available at https://www.eclipse.org/legal/epl-2.0/ |
| 7 | + * or the Apache License, Version 2.0 which accompanies this distribution and |
| 8 | + * is available at https://www.apache.org/licenses/LICENSE-2.0. |
| 9 | + * |
| 10 | + * This Source Code may also be made available under the following |
| 11 | + * Secondary Licenses when the conditions for such availability set |
| 12 | + * forth in the Eclipse Public License, v. 2.0 are satisfied: GNU |
| 13 | + * General Public License, version 2 with the GNU Classpath |
| 14 | + * Exception [1] and GNU General Public License, version 2 with the |
| 15 | + * OpenJDK Assembly Exception [2]. |
| 16 | + * |
| 17 | + * [1] https://www.gnu.org/software/classpath/license.html |
| 18 | + * [2] https://openjdk.org/legal/assembly-exception.html |
| 19 | + * |
| 20 | + * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0 |
| 21 | + */ |
| 22 | +package org.openj9.test; |
| 23 | + |
| 24 | +import com.ibm.oti.vm.VM; |
| 25 | + |
| 26 | +public class VMAPITest2 { |
| 27 | + public static void main(String[] args) throws Throwable { |
| 28 | + final WorkLoad workLoad = new WorkLoad(200, 20000, 200); |
| 29 | + |
| 30 | + Thread app = new Thread(() -> { |
| 31 | + workLoad.runWork(); |
| 32 | + }); |
| 33 | + app.start(); |
| 34 | + |
| 35 | + try { |
| 36 | + Thread.sleep(3000); |
| 37 | + } catch(Throwable t) { |
| 38 | + t.printStackTrace(); |
| 39 | + } |
| 40 | + |
| 41 | + if (VM.isJFRRecordingStarted()) { |
| 42 | + System.out.println("Failed should not be recording 1."); |
| 43 | + System.exit(0); |
| 44 | + } |
| 45 | + |
| 46 | + /* attempt a stop recording before it has started */ |
| 47 | + VM.stopJFR(); |
| 48 | + |
| 49 | + if (VM.isJFRRecordingStarted()) { |
| 50 | + System.out.println("Failed should not be recording 2."); |
| 51 | + System.exit(0); |
| 52 | + } |
| 53 | + |
| 54 | + VM.startJFR(); |
| 55 | + if (!VM.isJFRRecordingStarted()) { |
| 56 | + System.out.println("Failed should be recording 3."); |
| 57 | + System.exit(0); |
| 58 | + } |
| 59 | + |
| 60 | + |
| 61 | + /* attempt another start recording after one has already started */ |
| 62 | + VM.startJFR(); |
| 63 | + if (!VM.isJFRRecordingStarted()) { |
| 64 | + System.out.println("Failed should be recording 4."); |
| 65 | + System.exit(0); |
| 66 | + } |
| 67 | + |
| 68 | + VM.stopJFR(); |
| 69 | + if (VM.isJFRRecordingStarted()) { |
| 70 | + System.out.println("Failed should not be recording 5."); |
| 71 | + System.exit(0); |
| 72 | + } |
| 73 | + |
| 74 | + /* attempt a stop recording before it has started */ |
| 75 | + VM.stopJFR(); |
| 76 | + } |
| 77 | +} |
0 commit comments