blob: 6d1ff962da6fa6f58935e7acfc3ba4bc0eeb74ad [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 Hughes69f5bc62011-08-24 09:26:14 -070023struct JavaVMExt : public JavaVM {
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 Runtime* runtime;
Elliott Hughesbbd76712011-08-17 10:25:24 -070047
Elliott Hughes515a5bc2011-08-17 11:08:34 -070048 bool check_jni;
Elliott Hughes0af55432011-08-17 18:37:28 -070049 bool verbose_jni;
Elliott Hughes515a5bc2011-08-17 11:08:34 -070050
Elliott Hughesbbd76712011-08-17 10:25:24 -070051 // Used to hold references to pinned primitive arrays.
52 ReferenceTable pin_table;
Elliott Hughes6c1a3942011-08-17 15:00:06 -070053
54 // JNI global references.
Elliott Hughes18c07532011-08-18 15:50:51 -070055 Mutex* globals_lock;
Elliott Hughes6c1a3942011-08-17 15:00:06 -070056 IndirectReferenceTable globals;
57
58 // JNI weak global references.
Elliott Hughes18c07532011-08-18 15:50:51 -070059 Mutex* weak_globals_lock;
Elliott Hughes6c1a3942011-08-17 15:00:06 -070060 IndirectReferenceTable weak_globals;
Elliott Hughes0af55432011-08-17 18:37:28 -070061
62 std::map<std::string, SharedLibrary*> libraries;
Elliott Hughesf2682d52011-08-15 16:37:04 -070063};
64
Elliott Hughes69f5bc62011-08-24 09:26:14 -070065struct JNIEnvExt : public JNIEnv {
Elliott Hughes515a5bc2011-08-17 11:08:34 -070066 JNIEnvExt(Thread* self, bool check_jni);
Elliott Hughesbbd76712011-08-17 10:25:24 -070067
Elliott Hughes40ef99e2011-08-11 17:44:34 -070068 Thread* self;
Carl Shapiroea4dca82011-08-01 13:45:38 -070069
Elliott Hughes515a5bc2011-08-17 11:08:34 -070070 bool check_jni;
71
Elliott Hughes40ef99e2011-08-11 17:44:34 -070072 // Are we in a "critical" JNI call?
73 bool critical;
Carl Shapiro2ed144c2011-07-26 16:52:08 -070074
Elliott Hughesbbd76712011-08-17 10:25:24 -070075 // Entered JNI monitors, for bulk exit on thread detach.
Elliott Hughes6c1a3942011-08-17 15:00:06 -070076 ReferenceTable monitors;
77
78 // JNI local references.
79 IndirectReferenceTable locals;
Carl Shapiroea4dca82011-08-01 13:45:38 -070080};
81
Ian Rogersdf20fe02011-07-20 20:34:16 -070082} // namespace art
Carl Shapiroea4dca82011-08-01 13:45:38 -070083
Elliott Hughesb465ab02011-08-24 11:21:21 -070084std::ostream& operator<<(std::ostream& os, const jobjectRefType& rhs);
85
Ian Rogersdf20fe02011-07-20 20:34:16 -070086#endif // ART_SRC_JNI_INTERNAL_H_