blob: c8a5a3990b04f535096ae9009f87d9f9a3ee1e4d [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 <string>
13
Ian Rogersdf20fe02011-07-20 20:34:16 -070014namespace art {
15
Elliott Hughes814e4032011-08-23 12:07:56 -070016class ClassLoader;
Elliott Hughes79082e32011-08-25 12:07:32 -070017class Libraries;
18class Method;
Elliott Hughes18c07532011-08-18 15:50:51 -070019class Mutex;
Elliott Hughesf2682d52011-08-15 16:37:04 -070020class Runtime;
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
Elliott Hughes75770752011-08-24 17:52:38 -070027 /**
28 * Loads the given shared library. 'path' is an absolute pathname.
Elliott Hughes0af55432011-08-17 18:37:28 -070029 *
Elliott Hughes75770752011-08-24 17:52:38 -070030 * Returns 'true' on success. On failure, sets 'detail' to a
31 * human-readable description of the error.
Elliott Hughes0af55432011-08-17 18:37:28 -070032 */
Elliott Hughes75770752011-08-24 17:52:38 -070033 bool LoadNativeLibrary(const std::string& path, ClassLoader* class_loader, std::string& detail);
Elliott Hughesbbd76712011-08-17 10:25:24 -070034
Elliott Hughes79082e32011-08-25 12:07:32 -070035 /**
36 * Returns a pointer to the code for the native method 'm', found
37 * using dlsym(3) on every native library that's been loaded so far.
38 */
39 void* FindCodeForNativeMethod(Method* m);
40
Elliott Hughesf2682d52011-08-15 16:37:04 -070041 Runtime* runtime;
Elliott Hughesbbd76712011-08-17 10:25:24 -070042
Elliott Hughes515a5bc2011-08-17 11:08:34 -070043 bool check_jni;
Elliott Hughes0af55432011-08-17 18:37:28 -070044 bool verbose_jni;
Elliott Hughes515a5bc2011-08-17 11:08:34 -070045
Elliott Hughesbbd76712011-08-17 10:25:24 -070046 // Used to hold references to pinned primitive arrays.
Elliott Hughes75770752011-08-24 17:52:38 -070047 Mutex* pins_lock;
Elliott Hughesbbd76712011-08-17 10:25:24 -070048 ReferenceTable pin_table;
Elliott Hughes6c1a3942011-08-17 15:00:06 -070049
50 // JNI global references.
Elliott Hughes18c07532011-08-18 15:50:51 -070051 Mutex* globals_lock;
Elliott Hughes6c1a3942011-08-17 15:00:06 -070052 IndirectReferenceTable globals;
53
54 // JNI weak global references.
Elliott Hughes18c07532011-08-18 15:50:51 -070055 Mutex* weak_globals_lock;
Elliott Hughes6c1a3942011-08-17 15:00:06 -070056 IndirectReferenceTable weak_globals;
Elliott Hughes0af55432011-08-17 18:37:28 -070057
Elliott Hughes79082e32011-08-25 12:07:32 -070058 Mutex* libraries_lock;
59 Libraries* libraries;
Elliott Hughesf2682d52011-08-15 16:37:04 -070060};
61
Elliott Hughes69f5bc62011-08-24 09:26:14 -070062struct JNIEnvExt : public JNIEnv {
Elliott Hughes75770752011-08-24 17:52:38 -070063 JNIEnvExt(Thread* self, JavaVMExt* vm);
Elliott Hughesc1674ed2011-08-25 18:09:09 -070064 ~JNIEnvExt();
Elliott Hughesbbd76712011-08-17 10:25:24 -070065
Elliott Hughes40ef99e2011-08-11 17:44:34 -070066 Thread* self;
Elliott Hughes75770752011-08-24 17:52:38 -070067 JavaVMExt* vm;
Carl Shapiroea4dca82011-08-01 13:45:38 -070068
Elliott Hughes515a5bc2011-08-17 11:08:34 -070069 bool check_jni;
70
Elliott Hughes40ef99e2011-08-11 17:44:34 -070071 // Are we in a "critical" JNI call?
72 bool critical;
Carl Shapiro2ed144c2011-07-26 16:52:08 -070073
Elliott Hughesbbd76712011-08-17 10:25:24 -070074 // Entered JNI monitors, for bulk exit on thread detach.
Elliott Hughes6c1a3942011-08-17 15:00:06 -070075 ReferenceTable monitors;
76
77 // JNI local references.
78 IndirectReferenceTable locals;
Carl Shapiroea4dca82011-08-01 13:45:38 -070079};
80
Ian Rogersdf20fe02011-07-20 20:34:16 -070081} // namespace art
Carl Shapiroea4dca82011-08-01 13:45:38 -070082
Elliott Hughesb465ab02011-08-24 11:21:21 -070083std::ostream& operator<<(std::ostream& os, const jobjectRefType& rhs);
84
Ian Rogersdf20fe02011-07-20 20:34:16 -070085#endif // ART_SRC_JNI_INTERNAL_H_