Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to call class os functions defined in share/vm/runtime/os.hpp?

user1130419Jul 1 2014 — edited Jul 10 2014

HI. I haven't coded in C for some time, and no experience with JNI

I dabbled a bit in JNI and creating native functions.

I would like to know, how can I call Java VM os functions from my own libraries without much hassle? e.g. os::javaTimeMillis(), or os::active_processor_count() ?

#include "HelloWorld.h"

JNIEXPORT void JNICALL Java_HelloWorld_sayHi

  (JNIEnv *env, jclass clazz) {

  printf("Hello\n");

long x = os::javaTimeMillis(); // HOW TO DO THAT?

}

Including src/share/vm/runtime/os.hpp seems overkill with lot of dependencies?

http://hg.openjdk.java.net/jdk8/jdk8/hotspot/file/87ee5ee27509/src/share/vm/runtime/os.hpp

Could I create a custom header file copy-pasting parts from os.hpp to make some functions known?

And I don't want to java-call the native java methods that mapped to these os functions, but call C functions directly.

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Aug 7 2014
Added on Jul 1 2014
1 comment
1,435 views