blob: 5d89dd8a20b03f07089bc9bceb37c89641d62829 [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"
Ian Rogersdf20fe02011-07-20 20:34:16 -070012
Elliott Hughes0af55432011-08-17 18:37:28 -070013#include <map>
14#include <string>
15
Ian Rogersdf20fe02011-07-20 20:34:16 -070016namespace art {
17
Elliott Hughesf2682d52011-08-15 16:37:04 -070018class Runtime;
Elliott Hughes0af55432011-08-17 18:37:28 -070019class SharedLibrary;
Elliott Hughes40ef99e2011-08-11 17:44:34 -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);
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.
56 IndirectReferenceTable globals;
57
58 // JNI weak global references.
59 IndirectReferenceTable weak_globals;
Elliott Hughes0af55432011-08-17 18:37:28 -070060
61 std::map<std::string, SharedLibrary*> libraries;
Elliott Hughesf2682d52011-08-15 16:37:04 -070062};
63
Elliott Hughes40ef99e2011-08-11 17:44:34 -070064struct JNIEnvExt {
Elliott Hughes515a5bc2011-08-17 11:08:34 -070065 JNIEnvExt(Thread* self, bool check_jni);
Elliott Hughesbbd76712011-08-17 10:25:24 -070066
Elliott Hughesf2682d52011-08-15 16:37:04 -070067 // Must be first to correspond with JavaVM.
68 const struct JNINativeInterface* fns;
Ian Rogersdf20fe02011-07-20 20:34:16 -070069
Elliott Hughes40ef99e2011-08-11 17:44:34 -070070 Thread* self;
Carl Shapiroea4dca82011-08-01 13:45:38 -070071
Elliott Hughes515a5bc2011-08-17 11:08:34 -070072 bool check_jni;
73
Elliott Hughes40ef99e2011-08-11 17:44:34 -070074 // Are we in a "critical" JNI call?
75 bool critical;
Carl Shapiro2ed144c2011-07-26 16:52:08 -070076
Elliott Hughesbbd76712011-08-17 10:25:24 -070077 // Entered JNI monitors, for bulk exit on thread detach.
Elliott Hughes6c1a3942011-08-17 15:00:06 -070078 ReferenceTable monitors;
79
80 // JNI local references.
81 IndirectReferenceTable locals;
Carl Shapiroea4dca82011-08-01 13:45:38 -070082};
83
Ian Rogersdf20fe02011-07-20 20:34:16 -070084} // namespace art
Carl Shapiroea4dca82011-08-01 13:45:38 -070085
Ian Rogersdf20fe02011-07-20 20:34:16 -070086#endif // ART_SRC_JNI_INTERNAL_H_