Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/sa/LingeredAppWithNativeMethod.java
41149 views
1
2
/*
3
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
*
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
9
*
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
15
*
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
22
* questions.
23
*/
24
25
import java.util.Random;
26
import jdk.test.lib.apps.LingeredApp;
27
import jdk.test.lib.Utils;
28
29
public class LingeredAppWithNativeMethod extends LingeredApp {
30
31
public static final String THREAD_NAME = "NoFramePointerJNIFib";
32
private static final int UPPER_BOUND = 55;
33
private static final int LOWER_BOUND = 40;
34
private static final Random RNG = Utils.getRandomInstance();
35
36
static {
37
// JNI library compiled with no frame pointer info
38
System.loadLibrary("NoFramePointer");
39
}
40
41
public void callNative() {
42
// Call JNI code which does something compute
43
// intensive: fibonacci
44
// That is to ensure that the native bits run when
45
// jstack --mixed info is to be gathered.
46
// Results of fibonacci calculation from JNI are
47
// reported via callback(). That's where the process
48
// of calculating fibonacci restarts.
49
int num = (int) (RNG.nextDouble() * UPPER_BOUND);
50
while (num < LOWER_BOUND) {
51
num = (int) (RNG.nextDouble() * UPPER_BOUND);
52
}
53
System.out.print("fib(" + num + ") = ");
54
callJNI(this, num);
55
}
56
57
// Called from JNI library libNoFramePointer
58
private void callback(long val) {
59
System.out.println(val);
60
// Call native again so as to increase chances of
61
// being currently in JNI code when jstack --mixed
62
// runs.
63
callNative();
64
}
65
66
public static native void callJNI(Object target, int num);
67
68
public static void main(String[] args) {
69
LingeredAppWithNativeMethod app = new LingeredAppWithNativeMethod();
70
Thread fibonacci = new Thread(() -> {
71
app.callNative();
72
});
73
fibonacci.setName(THREAD_NAME);
74
fibonacci.start();
75
LingeredApp.main(args);
76
}
77
}
78
79