Skip to content

Commit 70f651d

Browse files
async-profiler#1174: Address feedback
1 parent 041df22 commit 70f651d

File tree

5 files changed

+23
-75
lines changed

5 files changed

+23
-75
lines changed

src/vmEntry.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,14 @@ static void* resolveMethodIdEnd() {
107107
}
108108

109109

110-
bool VM::init(JavaVM* vm, bool attach, bool attach_thread) {
110+
bool VM::init(JavaVM* vm, bool attach) {
111111
if (_jvmti != NULL) return true;
112112

113113
_vm = vm;
114114
if (_vm->GetEnv((void**)&_jvmti, JVMTI_VERSION_1_0) != 0) {
115115
return false;
116116
}
117117

118-
if (attach_thread) {
119-
JNIEnv* env = nullptr;
120-
if (_vm->AttachCurrentThreadAsDaemon((void**)&env, NULL) != JNI_OK) {
121-
return false;
122-
}
123-
}
124-
125118
bool is_hotspot = false;
126119
bool is_zero_vm = false;
127120
char* prop;
@@ -417,7 +410,7 @@ Agent_OnLoad(JavaVM* vm, char* options, void* reserved) {
417410
}
418411
}
419412

420-
if (!VM::init(vm, false, false)) {
413+
if (!VM::init(vm, false)) {
421414
Log::error("JVM does not support Tool Interface");
422415
return COMMAND_ERROR;
423416
}
@@ -437,7 +430,7 @@ Agent_OnAttach(JavaVM* vm, char* options, void* reserved) {
437430
return ARGUMENTS_ERROR;
438431
}
439432

440-
if (!VM::init(vm, true, false)) {
433+
if (!VM::init(vm, true)) {
441434
Log::error("JVM does not support Tool Interface");
442435
return COMMAND_ERROR;
443436
}
@@ -459,7 +452,7 @@ Agent_OnAttach(JavaVM* vm, char* options, void* reserved) {
459452

460453
extern "C" DLLEXPORT jint JNICALL
461454
JNI_OnLoad(JavaVM* vm, void* reserved) {
462-
if (!VM::init(vm, true, false)) {
455+
if (!VM::init(vm, true)) {
463456
return 0;
464457
}
465458

@@ -494,5 +487,5 @@ void VM::tryAttach() {
494487
if (result != JNI_OK || nVMs != 1) {
495488
return;
496489
}
497-
VM::init(jvm, true, true);
490+
VM::init(jvm, true);
498491
}

src/vmEntry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class VM {
118118
static JVM_MemoryFunc _totalMemory;
119119
static JVM_MemoryFunc _freeMemory;
120120

121-
static bool init(JavaVM* vm, bool attach, bool attach_thread);
121+
static bool init(JavaVM* vm, bool attach);
122122

123123
static bool loaded() {
124124
return _jvmti != NULL;

test/one/profiler/test/Runner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private static Jvm detectJvm() {
9191
return Jvm.HOTSPOT;
9292
}
9393

94-
private static int detectJvmVersion() {
94+
protected static int detectJvmVersion() {
9595
String prop = System.getProperty("java.vm.specification.version");
9696
if (prop.startsWith("1.")) {
9797
prop = prop.substring(2);

test/one/profiler/test/TestProcess.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,7 @@ public class TestProcess implements Closeable {
3434
public static final String TESTBIN = "%testbin";
3535

3636
private static final String JAVA_HOME = System.getProperty("java.home");
37-
private static final String JAVA_VERSION;
38-
39-
static {
40-
String[] javaVersionParts = System.getProperty("java.version").split("\\.");
41-
// JAVA 8 & lower are reported as 1.X... while higher versions are reported as X....
42-
if (javaVersionParts[0].equals("1")) {
43-
JAVA_VERSION = javaVersionParts[1];
44-
} else {
45-
JAVA_VERSION = javaVersionParts[0];
46-
}
47-
}
37+
private static final String JAVA_VERSION = Runner.detectJvmVersion() + "";
4838

4939
private static final Pattern filePattern = Pattern.compile("(%[a-z]+)(\\.[a-z]+)?");
5040

test/test/nonjava/non_java_app.cpp

Lines changed: 15 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,30 @@
99
#include <iostream>
1010
#include <limits.h>
1111
#include "asprof.h"
12+
13+
// detect arch for java 8
14+
#if defined(__x86_64__) || defined(_M_X64)
15+
# define JAVA8_ARCH_PATH "amd64/"
16+
#elif defined(__i386) || defined(_M_IX86)
17+
# define JAVA8_ARCH_PATH "i386/"
18+
#elif defined(__aarch64__) || defined(_M_ARM64)
19+
# define JAVA8_ARCH_PATH "aarch64/"
20+
#elif defined(__arm__) || defined(_M_ARM)
21+
# define JAVA8_ARCH_PATH "arm/"
22+
#else
23+
# define JAVA8_ARCH_PATH "/"
24+
#endif
1225

1326
#ifdef __linux__
1427
const char profiler_lib_path[] = "build/lib/libasyncProfiler.so";
1528
const char jvm_lib_path[] = "lib/server/libjvm.so";
16-
const char jvm8_lib_path[] = "lib/amd64/server/libjvm.so";
29+
const char jvm8_lib_path[] = "lib/" JAVA8_ARCH_PATH "server/libjvm.so";
1730
#else
1831
const char profiler_lib_path[] = "build/lib/libasyncProfiler.dylib";
1932
const char jvm_lib_path[] = "lib/server/libjvm.dylib";
2033
const char jvm8_lib_path[] = "lib/server/libjvm.dylib";
2134
#endif
2235

23-
#ifndef JNI_VERSION_9
24-
#define JNI_VERSION_9 0x00090000
25-
#endif
26-
27-
#ifndef JNI_VERSION_10
28-
#define JNI_VERSION_10 0x000a0000
29-
#endif
30-
31-
#ifndef JNI_VERSION_19
32-
#define JNI_VERSION_19 0x00130000
33-
#endif
34-
35-
#ifndef JNI_VERSION_20
36-
#define JNI_VERSION_20 0x00140000
37-
#endif
38-
39-
#ifndef JNI_VERSION_21
40-
#define JNI_VERSION_21 0x00150000
41-
#endif
42-
43-
#ifndef JNI_VERSION_24
44-
#define JNI_VERSION_24 0x00180000
45-
#endif
46-
4736
typedef jint (*CreateJvm)(JavaVM **, void **, void *);
4837

4938
asprof_init_t _asprof_init;
@@ -122,30 +111,6 @@ void loadJvmLib() {
122111
}
123112
}
124113

125-
int getJniVersion() {
126-
if (java_version == 8) {
127-
return JNI_VERSION_1_8;
128-
}
129-
130-
if (java_version == 9) {
131-
return JNI_VERSION_9;
132-
}
133-
134-
if (java_version >= 10 && java_version <= 18) {
135-
return JNI_VERSION_10;
136-
}
137-
138-
if (java_version == 19) {
139-
return JNI_VERSION_19;
140-
}
141-
142-
if (java_version >= 20 && java_version <= 23) {
143-
return JNI_VERSION_20;
144-
}
145-
146-
return JNI_VERSION_24;
147-
}
148-
149114
void startJvm() {
150115
// Start JVM
151116
JavaVMInitArgs vm_args;
@@ -156,7 +121,7 @@ void startJvm() {
156121
//options[1].optionString = const_cast<char*>("-Xcheck:jni");
157122

158123
// Configure JVM
159-
vm_args.version = getJniVersion();;
124+
vm_args.version = JNI_VERSION_1_6;
160125
vm_args.nOptions = 1;
161126
vm_args.options = options;
162127
vm_args.ignoreUnrecognized = true;

0 commit comments

Comments
 (0)