blob: d9a18323fb585c343421b5e8f1b8df5563bfc344 [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 Hughes814e4032011-08-23 12:07:56 -070017class ClassLoader;
Elliott Hughes18c07532011-08-18 15:50:51 -070018class Mutex;
Elliott Hughesf2682d52011-08-15 16:37:04 -070019class Runtime;
Elliott Hughes0af55432011-08-17 18:37:28 -070020class SharedLibrary;
Elliott Hughes18c07532011-08-18 15:50:51 -070021class Thread;
Ian Rogersdf20fe02011-07-20 20:34:16 -070022
Elliott Hughesf2682d52011-08-15 16:37:04 -070023struct JavaVMExt {
Elliott Hughes0af55432011-08-17 18:37:28 -070024 JavaVMExt(Runtime* runtime, bool check_jni, bool verbose_jni);
Elliott Hughesde69d7f2011-08-18 16:49:37 -070025 ~JavaVMExt();
Elliott Hughes0af55432011-08-17 18:37:28 -070026
27 /*
28 * Load native code from the specified absolute pathname. Per the spec,
29 * if we've already loaded a library with the specified pathname, we
30 * return without doing anything.
31 *
32 * TODO: for better results we should canonicalize the pathname. For fully
33 * correct results we should stat to get the inode and compare that. The
34 * existing implementation is fine so long as everybody is using
35 * System.loadLibrary.
36 *
37 * The library will be associated with the specified class loader. The JNI
38 * spec says we can't load the same library into more than one class loader.
39 *
40 * Returns true on success. On failure, returns false and sets *detail to a
41 * human-readable description of the error or NULL if no detail is
42 * available; ownership of the string is transferred to the caller.
43 */
Elliott Hughes814e4032011-08-23 12:07:56 -070044 bool LoadNativeLibrary(const std::string& path, ClassLoader* class_loader, char** detail);
Elliott Hughesbbd76712011-08-17 10:25:24 -070045
Elliott Hughesf2682d52011-08-15 16:37:04 -070046 // Must be first to correspond with JNIEnv.
47 const struct JNIInvokeInterface* fns;
48
49 Runtime* runtime;
Elliott Hughesbbd76712011-08-17 10:25:24 -070050
Elliott Hughes515a5bc2011-08-17 11:08:34 -070051 bool check_jni;
Elliott Hughes0af55432011-08-17 18:37:28 -070052 bool verbose_jni;
Elliott Hughes515a5bc2011-08-17 11:08:34 -070053
Elliott Hughesbbd76712011-08-17 10:25:24 -070054 // Used to hold references to pinned primitive arrays.
55 ReferenceTable pin_table;
Elliott Hughes6c1a3942011-08-17 15:00:06 -070056
57 // JNI global references.
Elliott Hughes18c07532011-08-18 15:50:51 -070058 Mutex* globals_lock;
Elliott Hughes6c1a3942011-08-17 15:00:06 -070059 IndirectReferenceTable globals;
60
61 // JNI weak global references.
Elliott Hughes18c07532011-08-18 15:50:51 -070062 Mutex* weak_globals_lock;
Elliott Hughes6c1a3942011-08-17 15:00:06 -070063 IndirectReferenceTable weak_globals;
Elliott Hughes0af55432011-08-17 18:37:28 -070064
65 std::map<std::string, SharedLibrary*> libraries;
Elliott Hughesf2682d52011-08-15 16:37:04 -070066};
67
Elliott Hughes40ef99e2011-08-11 17:44:34 -070068struct JNIEnvExt {
Elliott Hughes515a5bc2011-08-17 11:08:34 -070069 JNIEnvExt(Thread* self, bool check_jni);
Elliott Hughesbbd76712011-08-17 10:25:24 -070070
Elliott Hughesf2682d52011-08-15 16:37:04 -070071 // Must be first to correspond with JavaVM.
72 const struct JNINativeInterface* fns;
Ian Rogersdf20fe02011-07-20 20:34:16 -070073
Elliott Hughes40ef99e2011-08-11 17:44:34 -070074 Thread* self;
Carl Shapiroea4dca82011-08-01 13:45:38 -070075
Elliott Hughes515a5bc2011-08-17 11:08:34 -070076 bool check_jni;
77
Elliott Hughes40ef99e2011-08-11 17:44:34 -070078 // Are we in a "critical" JNI call?
79 bool critical;
Carl Shapiro2ed144c2011-07-26 16:52:08 -070080
Elliott Hughesbbd76712011-08-17 10:25:24 -070081 // Entered JNI monitors, for bulk exit on thread detach.
Elliott Hughes6c1a3942011-08-17 15:00:06 -070082 ReferenceTable monitors;
83
84 // JNI local references.
85 IndirectReferenceTable locals;
Carl Shapiroea4dca82011-08-01 13:45:38 -070086};
87
Ian Rogersdf20fe02011-07-20 20:34:16 -070088} // namespace art
Carl Shapiroea4dca82011-08-01 13:45:38 -070089
Ian Rogersdf20fe02011-07-20 20:34:16 -070090#endif // ART_SRC_JNI_INTERNAL_H_