author | sgehwolf |
Thu, 14 Mar 2019 14:04:39 +0100 | |
changeset 54824 | adb3a3aa2e52 |
permissions | -rw-r--r-- |
54824
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
1 |
/* |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Red Hat, Inc |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
4 |
* |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
8 |
* |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
13 |
* accompanied this code). |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
14 |
* |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
18 |
* |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
21 |
* questions. |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
22 |
*/ |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
23 |
package fib; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
24 |
public class FibJNI { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
25 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
26 |
static { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
27 |
// Native lib used for debug symbols stripping |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
28 |
System.loadLibrary("Fib"); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
29 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
30 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
31 |
private final int num; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
32 |
private final long expected; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
33 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
34 |
public FibJNI(int num, long expected) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
35 |
this.num = num; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
36 |
this.expected = expected; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
37 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
38 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
39 |
public void callNative() { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
40 |
callJNI(this, num); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
41 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
42 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
43 |
// Called from JNI library libFib |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
44 |
private void callback(long val) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
45 |
System.out.println("Debug: result was: " + val); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
46 |
if (val != expected) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
47 |
throw new RuntimeException("Expected " + expected + " but got: " +val); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
48 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
49 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
50 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
51 |
public static native void callJNI(Object target, int num); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
52 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
53 |
public static void main(String[] args) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
54 |
if (args.length != 2) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
55 |
System.err.println("Usage: " + FibJNI.class.getName() + " <input> <expectedResult>"); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
56 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
57 |
int input = Integer.parseInt(args[0]); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
58 |
long expected = Long.parseLong(args[1]); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
59 |
FibJNI fib = new FibJNI(input, expected); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
60 |
fib.callNative(); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
61 |
System.out.println("DEBUG: Sanity check for " + FibJNI.class.getSimpleName() + " passed."); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
62 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
63 |
} |