blob: a6fce054ee48476b564e2ac8d9dabeef5f37b7fb [file] [log] [blame]
Ian Rogersdf20fe02011-07-20 20:34:16 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
3#ifndef ART_SRC_JNI_INTERNAL_H_
4#define ART_SRC_JNI_INTERNAL_H_
5
6#include "jni.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07007
Elliott Hughes6c1a3942011-08-17 15:00:06 -07008#include "indirect_reference_table.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07009#include "macros.h"
Elliott Hughesbbd76712011-08-17 10:25:24 -070010#include "reference_table.h"
Ian Rogersdf20fe02011-07-20 20:34:16 -070011
Elliott Hughes0af55432011-08-17 18:37:28 -070012#include <map>
13#include <string>
14
Ian Rogersdf20fe02011-07-20 20:34:16 -070015namespace art {
16
Elliott Hughes18c07532011-08-18 15:50:51 -070017class Mutex;
Elliott Hughesf2682d52011-08-15 16:37:04 -070018class Runtime;
Elliott Hughes0af55432011-08-17 18:37:28 -070019class SharedLibrary;
Elliott Hughes18c07532011-08-18 15:50:51 -070020class Thread;
Ian Rogersdf20fe02011-07-20 20:34:16 -070021
Elliott Hughesf2682d52011-08-15 16:37:04 -070022struct JavaVMExt {
Elliott Hughes0af55432011-08-17 18:37:28 -070023 JavaVMExt(Runtime* runtime, bool check_jni, bool verbose_jni);
Elliott Hughesde69d7f2011-08-18 16:49:37 -070024 ~JavaVMExt();
Elliott Hughes0af55432011-08-17 18:37:28 -070025
26 /*
27 * Load native code from the specified absolute pathname. Per the spec,
28 * if we've already loaded a library with the specified pathname, we
29 * return without doing anything.
30 *
31 * TODO: for better results we should canonicalize the pathname. For fully
32 * correct results we should stat to get the inode and compare that. The
33 * existing implementation is fine so long as everybody is using
34 * System.loadLibrary.
35 *
36 * The library will be associated with the specified class loader. The JNI
37 * spec says we can't load the same library into more than one class loader.
38 *
39 * Returns true on success. On failure, returns false and sets *detail to a
40 * human-readable description of the error or NULL if no detail is
41 * available; ownership of the string is transferred to the caller.
42 */
43 bool LoadNativeLibrary(const std::string& path, Object* class_loader, char** detail);
Elliott Hughesbbd76712011-08-17 10:25:24 -070044
Elliott Hughesf2682d52011-08-15 16:37:04 -070045 // Must be first to correspond with JNIEnv.
46 const struct JNIInvokeInterface* fns;
47
48 Runtime* runtime;
Elliott Hughesbbd76712011-08-17 10:25:24 -070049
Elliott Hughes515a5bc2011-08-17 11:08:34 -070050 bool check_jni;
Elliott Hughes0af55432011-08-17 18:37:28 -070051 bool verbose_jni;
Elliott Hughes515a5bc2011-08-17 11:08:34 -070052
Elliott Hughesbbd76712011-08-17 10:25:24 -070053 // Used to hold references to pinned primitive arrays.
54 ReferenceTable pin_table;
Elliott Hughes6c1a3942011-08-17 15:00:06 -070055
56 // JNI global references.
Elliott Hughes18c07532011-08-18 15:50:51 -070057 Mutex* globals_lock;
Elliott Hughes6c1a3942011-08-17 15:00:06 -070058 IndirectReferenceTable globals;
59
60 // JNI weak global references.
Elliott Hughes18c07532011-08-18 15:50:51 -070061 Mutex* weak_globals_lock;
Elliott Hughes6c1a3942011-08-17 15:00:06 -070062 IndirectReferenceTable weak_globals;
Elliott Hughes0af55432011-08-17 18:37:28 -070063
64 std::map<std::string, SharedLibrary*> libraries;
Elliott Hughesf2682d52011-08-15 16:37:04 -070065};
66
Elliott Hughes40ef99e2011-08-11 17:44:34 -070067struct JNIEnvExt {
Elliott Hughes515a5bc2011-08-17 11:08:34 -070068 JNIEnvExt(Thread* self, bool check_jni);
Elliott Hughesbbd76712011-08-17 10:25:24 -070069
Elliott Hughesf2682d52011-08-15 16:37:04 -070070 // Must be first to correspond with JavaVM.
71 const struct JNINativeInterface* fns;
Ian Rogersdf20fe02011-07-20 20:34:16 -070072
Elliott Hughes40ef99e2011-08-11 17:44:34 -070073 Thread* self;
Carl Shapiroea4dca82011-08-01 13:45:38 -070074
Elliott Hughes515a5bc2011-08-17 11:08:34 -070075 bool check_jni;
76
Elliott Hughes40ef99e2011-08-11 17:44:34 -070077 // Are we in a "critical" JNI call?
78 bool critical;
Carl Shapiro2ed144c2011-07-26 16:52:08 -070079
Elliott Hughesbbd76712011-08-17 10:25:24 -070080 // Entered JNI monitors, for bulk exit on thread detach.
Elliott Hughes6c1a3942011-08-17 15:00:06 -070081 ReferenceTable monitors;
82
83 // JNI local references.
84 IndirectReferenceTable locals;
Carl Shapiroea4dca82011-08-01 13:45:38 -070085};
86
Ian Rogersdf20fe02011-07-20 20:34:16 -070087} // namespace art
Carl Shapiroea4dca82011-08-01 13:45:38 -070088
Ian Rogersdf20fe02011-07-20 20:34:16 -070089#endif // ART_SRC_JNI_INTERNAL_H_