72 for (; (c = *it) !=
')'; ++it) {
89 while ((++it, c = *it) !=
';') {
90 if (((c >=
'a') && (c <=
'z')) ||
91 ((c >=
'A') && (c <=
'Z')) ||
92 ((c >=
'0') && (c <=
'9'))) {
153 for (
s4 i = 0;
i < 4; ++
i) {
155 tmp[3 -
i] = (val > 10) ? (
'a' + val - 10) : (
'0' + val);
188 begin = classname.
begin();
189 end = classname.
end();
191 for (; begin != end; ++begin) {
199 begin = methodname.
begin();
200 end = methodname.
end();
202 for (; begin != end; ++begin) {
245 for (
size_t i = 0;
i < count;
i++) {
247 printf(
"[Registering JNI native method ");
256 NativeMethod nm(classname, name, signature, methods[
i].fnPtr);
275 printf(
"[Dynamic-linking native method ");
301 #if defined(ENABLE_DL)
303 if (symbol == NULL) {
316 # if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
317 if (symbol == NULL) {
325 utf8::java_lang_ClassLoader_java_lang_String__J,
329 if (method_findNative != NULL) {
335 if (symbol == NULL) {
349 if (symbol == NULL) {
383 std::set<NativeMethod>::iterator it =
_methods.find(nm);
388 return (*it).get_function();
397 #if defined(ENABLE_DL)
401 printf(
"[Loading native library ");
433 #if defined(ENABLE_DL)
437 printf(
"[Unloading native library ");
471 #if defined(ENABLE_DL)
487 # if defined(ENABLE_JNI)
491 if (onload != NULL) {
492 JNIEXPORT jint (JNICALL *JNI_OnLoad) (
JavaVM*,
void*);
495 JNI_OnLoad = (JNIEXPORT jint (JNICALL *)(JavaVM*,
void*)) (uintptr_t) onload;
499 jint
version = JNI_OnLoad(vm, NULL);
503 if ((version != JNI_VERSION_1_2) && (version != JNI_VERSION_1_4)) {
512 nativelibraries.
add(*
this);
516 os::abort(
"NativeLibrary::load: Not available in this configuration.");
529 #if defined(ENABLE_DL)
556 #if defined(ENABLE_DL)
584 if (its.first == its.second)
587 MAP::const_iterator it = find_if(its.first, its.second, std::bind2nd(
comparator(), library.
get_filename()));
590 if (it == its.second)
608 std::pair<MAP::const_iterator, MAP::const_iterator> its =
_libraries.equal_range(classloader);
612 if (its.first == its.second)
615 for (MAP::const_iterator it = its.first; it != its.second; it++) {
634 #if defined(ENABLE_JVMTI)
635 void NativeAgents::register_agent_library(
char* library,
char* options)
637 NativeAgent na(library, options);
640 _agents.push_back(na);
652 #if defined(ENABLE_JVMTI)
653 void NativeAgents::register_agent_path(
char* path,
char* options)
655 os::abort(
"NativeAgents::register_agent_library: Implement me!");
668 #if defined(ENABLE_JVMTI)
669 bool NativeAgents::load_agents()
672 for (std::vector<NativeAgent>::iterator it = _agents.begin(); it != _agents.end(); ++it) {
673 NativeAgent& na = *(it);
679 .
write(na.get_library())
687 if (
nl.open() == NULL)
691 void* onload =
os::dlsym(
nl.get_handle(),
"Agent_OnLoad");
694 if (onload != NULL) {
698 Agent_OnLoad = (JNIEXPORT jint (JNICALL *)(JavaVM*,
char*,
void*)) (uintptr_t) onload;
712 log_println(
"NativeAgents::load_agents: Native agent library does not export Agent_OnLoad");
735 vm_abort(
"native_new_and_init: c == NULL");
768 vm_abort(
"native_new_and_init_string: c == NULL");
Utf8String utf8_str()
get utf-8 string contents of buffer as utf8-string
Utf8String _classname
Class name.
static Utf8String native_method_symbol(Utf8String classname, Utf8String methodname)
methodinfo * class_resolveclassmethod(classinfo *c, Utf8String name, Utf8String desc, classinfo *referer, bool throwexception)
Utf8String get_filename() const
void * open()
Open this native library.
void native_resolved(methodinfo *m, void *symbol, void **symbolptr)
void register_methods(Utf8String classname, const JNINativeMethod *methods, size_t count)
Register native methods with the VM.
classloader_t * get_classloader() const
void close()
Close this native library.
static JavaString from_utf8(Utf8String)
byte_iterator end() const
void utf_display_printable_ascii_classname(Utf8String u)
typedef void(JNICALL *jvmtiEventSingleStep)(jvmtiEnv *jvmti_env
void * resolve_symbol(Utf8String symbolname, classloader_t *classloader)
Try to find a symbol with the given name in all loaded native libraries defined by classloader...
bool operator<(const NativeMethod &first, const NativeMethod &second)
int64_t vm_call_method_long(methodinfo *m, java_handle_t *o,...)
java_handle_t * vm_call_method(methodinfo *m, java_handle_t *o,...)
JNIEnv jclass jobject const char * name
void log_println(const char *text,...)
methodinfo * class_findmethod(classinfo *c, Utf8String name, Utf8String desc)
static classloader_t * class_get_classloader(classinfo *c)
Utf8String _name
Method name.
#define NATIVE_LIBRARY_PREFIX
java_handle_t * builtin_new(classinfo *c)
void vm_abort(const char *text,...)
static void * dlsym(void *handle, const char *symbol)
bool load(JNIEnv *env)
Load this native library and initialize it, if possible.
const char * byte_iterator
std::set< NativeMethod > _methods
NativeLibraries & get_nativelibraries()
bool is_loaded()
Checks if this native library is loaded.
static void * dlopen(const char *filename, int flag)
static Utf8String native_make_overloaded_function(Utf8String name, Utf8String descriptor)
Instruction::InstID tmp[]
static void version(bool opt_exit)
static JNINativeMethod methods[]
void exceptions_throw_nullpointerexception(void)
utf16_iterator utf16_begin() const
static char * dlerror(void)
static Utf8String from_utf8(const char *, size_t)
bool is_loaded(NativeLibrary &library)
Checks if the given native library is loaded.
void * _handle
Filesystem handle.
Represents a native library.
void add(NativeLibrary &library)
Add the given native library to the native libraries table.
Utf8String _descriptor
Method signature.
void * find_registered_method(methodinfo *m)
Try to find the given method in the native methods registered with the VM.
void utf_display_printable_ascii(Utf8String u)
void * resolve_method(methodinfo *m)
Resolves a native method, maybe from a dynamic library.
java_handle_t * native_new_and_init(classinfo *c)
Registers a new native agent by specified by it's library name and with an optional options string...
Utf8String _filename
Name of the native library.
Mutex _mutex
Mutex to make the container thread-safe.
JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
#define NATIVE_LIBRARY_SUFFIX
byte_iterator begin() const
Table containing all loaded native libraries.
void unlock()
Unlocks the given mutex object and checks for errors.
java_handle_t * native_new_and_init_string(classinfo *c, java_handle_t *s)
void * resolve_symbol(Utf8String symbolname) const
Resolve the given symbol in this native library.
void exceptions_throw_unsatisfiedlinkerror(Utf8String name)
Represents a native method.
void lock()
Locks the given mutex object and checks for errors.
classinfo * class_java_lang_ClassLoader
static int dlclose(void *handle)
static VM * get_current()
static void native_insert_char(Buffer<> &name, u2 c)