I am hacking JVM9 source code, especially class os
part.
What I am trying to do is:
(1) add a static int
array named gc_tid[64]
to store some thread id information.
(2) add a static int nr_gc_tid;
to count the number of threads above
So, I only add another two members in class os
here, similar to the previous variable member
static size_t _page_sizes[page_sizes_max];
.
(Everything I did here is to mimic how _page_sizes
is declared in os.hpp
)
class os: AllStatic {
public:
...
static int gc_tid[64];
static int nr_gc_tid;
...
};
I also have to do initialization of both nr_gc_tid
and gc_tid[64]
.
So, I write a static void init_gc_tid(void)
in
hotspot/src/share/vm/runtime/os.hpp
before here as a public
member function.
static void init_gc_tid(void);
Then, I define this function init_gc_tid(void)
in hotspot/src/os/linux/vm/os_linux.cpp
just before void os::init(void)
(Everything I did here is to mimic how os::init(void)
is declared in os.hpp
, and is defined in os_linux.cpp
)
void os::init_gc_tid(void){
//step 1: init nr_gctid as 0
nr_gc_tid = 0;
//step 2: init all gc tid as -100
int i = 0;
for(i = 0; i < 64; ++i){
gc_tid[i] = -100;
}
}
Finally, I call my init_gc_tid
function in os::init(void)
after init_page_sizes((size_t) Linux::page_size());
here.
But it doesn't work. When I make
the JVM9 project. I get errors like
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Compiling 11 properties into resource bundles for java.logging
Compiling 3 files for COMPILE_CREATE_SYMBOLS
Compiling 11 properties into resource bundles for jdk.management.agent
Compiling 3 properties into resource bundles for jdk.jdi
Compiling 2 files for BUILD_BREAKITERATOR_BASE
Compiling 11 properties into resource bundles for jdk.jartool
Compiling 2 files for BUILD_BREAKITERATOR_LD
Compiling 4 properties into resource bundles for jdk.jlink
Compiling 3 properties into resource bundles for jdk.jlink
Compiling 1 properties into resource bundles for jdk.jlink
Compiling 224 properties into resource bundles for jdk.localedata
Creating buildtools/jdk.vm.compiler.replacements.verifier.jar
Compiling 6 properties into resource bundles for java.base
Compiling 11 properties into resource bundles for java.base
Creating ct.sym classes
Creating buildtools/jdk.vm.compiler.match.processor.jar
Creating support/symbols/ct.sym
Compiling 100 properties into resource bundles for java.desktop
Compiling 2897 files for java.base
/home/wxf/sandboxJDK/9jdk/build/linux-x86_64-normal-server-slowdebug/hotspot/variant-server/libjvm/objs/os_linux.o: In function `os::init_gc_tid()':
/home/wxf/sandboxJDK/9jdk/hotspot/src/os/linux/vm/os_linux.cpp:4726: undefined reference to `os::nr_gc_tid'
/home/wxf/sandboxJDK/9jdk/hotspot/src/os/linux/vm/os_linux.cpp:4730: undefined reference to `os::gc_tid'
collect2: error: ld returned 1 exit status
make[3]: *** [/home/wxf/sandboxJDK/9jdk/build/linux-x86_64-normal-server-slowdebug/support/modules_libs/java.base/server/libjvm.so] Error 1
lib/CompileJvm.gmk:207: recipe for target '/home/wxf/sandboxJDK/9jdk/build/linux-x86_64-normal-server-slowdebug/support/modules_libs/java.base/server/libjvm.so' failed
make[3]: *** Waiting for unfinished jobs....
/home/wxf/sandboxJDK/9jdk/build/linux-x86_64-normal-server-slowdebug/hotspot/variant-server/libjvm/objs/os_linux.o: In function `os::init_gc_tid()':
/home/wxf/sandboxJDK/9jdk/hotspot/src/os/linux/vm/os_linux.cpp:4726: undefined reference to `os::nr_gc_tid'
/home/wxf/sandboxJDK/9jdk/hotspot/src/os/linux/vm/os_linux.cpp:4730: undefined reference to `os::gc_tid'
collect2: error: ld returned 1 exit status
lib/CompileGtest.gmk:64: recipe for target '/home/wxf/sandboxJDK/9jdk/build/linux-x86_64-normal-server-slowdebug/hotspot/variant-server/libjvm/gtest/libjvm.so' failed
make[3]: *** [/home/wxf/sandboxJDK/9jdk/build/linux-x86_64-normal-server-slowdebug/hotspot/variant-server/libjvm/gtest/libjvm.so] Error 1
make/Main.gmk:263: recipe for target 'hotspot-server-libs' failed
make[2]: *** [hotspot-server-libs] Error 2
make[2]: *** Waiting for unfinished jobs....
ERROR: Build failed for target 'default (exploded-image)' in configuration 'linux-x86_64-normal-server-slowdebug' (exit code 2)
Stopping sjavac server
=== Output from failing command(s) repeated here ===
* For target hotspot_variant-server_libjvm_gtest_objs_BUILD_GTEST_LIBJVM_link:
/home/wxf/sandboxJDK/9jdk/build/linux-x86_64-normal-server-slowdebug/hotspot/variant-server/libjvm/objs/os_linux.o: In function `os::init_gc_tid()':
/home/wxf/sandboxJDK/9jdk/hotspot/src/os/linux/vm/os_linux.cpp:4726: undefined reference to `os::nr_gc_tid'
/home/wxf/sandboxJDK/9jdk/hotspot/src/os/linux/vm/os_linux.cpp:4730: undefined reference to `os::gc_tid'
collect2: error: ld returned 1 exit status
* For target hotspot_variant-server_libjvm_objs_BUILD_LIBJVM_link:
/home/wxf/sandboxJDK/9jdk/build/linux-x86_64-normal-server-slowdebug/hotspot/variant-server/libjvm/objs/os_linux.o: In function `os::init_gc_tid()':
/home/wxf/sandboxJDK/9jdk/hotspot/src/os/linux/vm/os_linux.cpp:4726: undefined reference to `os::nr_gc_tid'
/home/wxf/sandboxJDK/9jdk/hotspot/src/os/linux/vm/os_linux.cpp:4730: undefined reference to `os::gc_tid'
collect2: error: ld returned 1 exit status
* All command lines available in /home/wxf/sandboxJDK/9jdk/build/linux-x86_64-normal-server-slowdebug/make-support/failure-logs.
=== End of repeated output ===
=== Make failed targets repeated here ===
lib/CompileJvm.gmk:207: recipe for target '/home/wxf/sandboxJDK/9jdk/build/linux-x86_64-normal-server-slowdebug/support/modules_libs/java.base/server/libjvm.so' failed
lib/CompileGtest.gmk:64: recipe for target '/home/wxf/sandboxJDK/9jdk/build/linux-x86_64-normal-server-slowdebug/hotspot/variant-server/libjvm/gtest/libjvm.so' failed
make/Main.gmk:263: recipe for target 'hotspot-server-libs' failed
=== End of repeated output ===
Hint: Try searching the build log for the name of the first failed target.
Hint: If caused by a warning, try configure --disable-warnings-as-errors.
/home/wxf/sandboxJDK/9jdk/make/Init.gmk:291: recipe for target 'main' failed
make[1]: *** [main] Error 2
/home/wxf/sandboxJDK/9jdk/make/Init.gmk:185: recipe for target 'default' failed
make: *** [default] Error 2
undefined reference to `os::nr_gc_tid'
undefined reference to `os::gc_tid'
This post helps, static variable link error
add
int os:: gc_tid[64];
int os:: nr_gc_tid;
at the beginning of os_linux.cpp
file