blob: 74366d3eea39193d4e7fac6a5760a75a5ad2667f [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
8#include "assembler.h"
Elliott Hughes6c1a3942011-08-17 15:00:06 -07009#include "indirect_reference_table.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070010#include "macros.h"
Elliott Hughesbbd76712011-08-17 10:25:24 -070011#include "reference_table.h"
Elliott Hughesc5f7c912011-08-18 14:00:42 -070012#include "thread.h"
Ian Rogersdf20fe02011-07-20 20:34:16 -070013
Elliott Hughes0af55432011-08-17 18:37:28 -070014#include <map>
15#include <string>
16
Ian Rogersdf20fe02011-07-20 20:34:16 -070017namespace art {
18
Elliott Hughesf2682d52011-08-15 16:37:04 -070019class Runtime;
Elliott Hughes0af55432011-08-17 18:37:28 -070020class SharedLibrary;
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);
24
25 /*
26 * Load native code from the specified absolute pathname. Per the spec,
27 * if we've already loaded a library with the specified pathname, we
28 * return without doing anything.
29 *
30 * TODO: for better results we should canonicalize the pathname. For fully
31 * correct results we should stat to get the inode and compare that. The
32 * existing implementation is fine so long as everybody is using
33 * System.loadLibrary.
34 *
35 * The library will be associated with the specified class loader. The JNI
36 * spec says we can't load the same library into more than one class loader.
37 *
38 * Returns true on success. On failure, returns false and sets *detail to a
39 * human-readable description of the error or NULL if no detail is
40 * available; ownership of the string is transferred to the caller.
41 */
42 bool LoadNativeLibrary(const std::string& path, Object* class_loader, char** detail);
Elliott Hughesbbd76712011-08-17 10:25:24 -070043
Elliott Hughesf2682d52011-08-15 16:37:04 -070044 // Must be first to correspond with JNIEnv.
45 const struct JNIInvokeInterface* fns;
46
47 Runtime* runtime;
Elliott Hughesbbd76712011-08-17 10:25:24 -070048
Elliott Hughes515a5bc2011-08-17 11:08:34 -070049 bool check_jni;
Elliott Hughes0af55432011-08-17 18:37:28 -070050 bool verbose_jni;
Elliott Hughes515a5bc2011-08-17 11:08:34 -070051
Elliott Hughesbbd76712011-08-17 10:25:24 -070052 // Used to hold references to pinned primitive arrays.
53 ReferenceTable pin_table;
Elliott Hughes6c1a3942011-08-17 15:00:06 -070054
55 // JNI global references.
Elliott Hughesc5f7c912011-08-18 14:00:42 -070056 Mutex globals_lock;
Elliott Hughes6c1a3942011-08-17 15:00:06 -070057 IndirectReferenceTable globals;
58
59 // JNI weak global references.
Elliott Hughesc5f7c912011-08-18 14:00:42 -070060 Mutex weak_globals_lock;
Elliott Hughes6c1a3942011-08-17 15:00:06 -070061 IndirectReferenceTable weak_globals;
Elliott Hughes0af55432011-08-17 18:37:28 -070062
63 std::map<std::string, SharedLibrary*> libraries;
Elliott Hughesf2682d52011-08-15 16:37:04 -070064};
65
Elliott Hughes40ef99e2011-08-11 17:44:34 -070066struct JNIEnvExt {
Elliott Hughes515a5bc2011-08-17 11:08:34 -070067 JNIEnvExt(Thread* self, bool check_jni);
Elliott Hughesbbd76712011-08-17 10:25:24 -070068
Elliott Hughesf2682d52011-08-15 16:37:04 -070069 // Must be first to correspond with JavaVM.
70 const struct JNINativeInterface* fns;
Ian Rogersdf20fe02011-07-20 20:34:16 -070071
Elliott Hughes40ef99e2011-08-11 17:44:34 -070072 Thread* self;
Carl Shapiroea4dca82011-08-01 13:45:38 -070073
Elliott Hughes515a5bc2011-08-17 11:08:34 -070074 bool check_jni;
75
Elliott Hughes40ef99e2011-08-11 17:44:34 -070076 // Are we in a "critical" JNI call?
77 bool critical;
Carl Shapiro2ed144c2011-07-26 16:52:08 -070078
Elliott Hughesbbd76712011-08-17 10:25:24 -070079 // Entered JNI monitors, for bulk exit on thread detach.
Elliott Hughes6c1a3942011-08-17 15:00:06 -070080 ReferenceTable monitors;
81
82 // JNI local references.
83 IndirectReferenceTable locals;
Carl Shapiroea4dca82011-08-01 13:45:38 -070084};
85
Ian Rogersdf20fe02011-07-20 20:34:16 -070086} // namespace art
Carl Shapiroea4dca82011-08-01 13:45:38 -070087
Ian Rogersdf20fe02011-07-20 20:34:16 -070088#endif // ART_SRC_JNI_INTERNAL_H_