diff options
author | 2016-08-11 10:48:03 -0700 | |
---|---|---|
committer | 2016-08-11 13:55:03 -0700 | |
commit | 185d134a3b43ab7529053e965917e0fa74bceba4 (patch) | |
tree | 5d3d0cee3aa4c64fc5f36fd5f648e53f6df984ae /runtime/java_vm_ext.h | |
parent | 7233c7e752c0d26387d143ee74420e9cd1f09390 (diff) |
Add basic runtime-plugins support.
This allows one to pass shared-libraries on the command line that the
runtime will load as plugins. They have access to runtime code and can
install hooks to add functionality. Currently the only hook they can
touch is JavaVMExt::AddEnvironmentHook to register a callback for
GetEnv(). More hooks might be added in the future.
Test: ./test/run-test 900
Change-Id: I852b4daf5a3fa71e9888722bc07794632c0e5010
Diffstat (limited to 'runtime/java_vm_ext.h')
-rw-r--r-- | runtime/java_vm_ext.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/runtime/java_vm_ext.h b/runtime/java_vm_ext.h index 3d055cd7ce..ed9d3abfe2 100644 --- a/runtime/java_vm_ext.h +++ b/runtime/java_vm_ext.h @@ -36,6 +36,10 @@ class ParsedOptions; class Runtime; struct RuntimeArgumentMap; +class JavaVMExt; +// Hook definition for runtime plugins. +using GetEnvHook = jint (*)(JavaVMExt* vm, /*out*/void** new_env, jint version); + class JavaVMExt : public JavaVM { public: JavaVMExt(Runtime* runtime, const RuntimeArgumentMap& runtime_options); @@ -171,6 +175,12 @@ class JavaVMExt : public JavaVM { void TrimGlobals() SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!globals_lock_); + jint HandleGetEnv(/*out*/void** env, jint version); + + void AddEnvironmentHook(GetEnvHook hook); + + static bool IsBadJniVersion(int version); + private: // Return true if self can currently access weak globals. bool MayAccessWeakGlobalsUnlocked(Thread* self) const SHARED_REQUIRES(Locks::mutator_lock_); @@ -215,6 +225,9 @@ class JavaVMExt : public JavaVM { Atomic<bool> allow_accessing_weak_globals_; ConditionVariable weak_globals_add_condition_ GUARDED_BY(weak_globals_lock_); + // TODO Maybe move this to Runtime. + std::vector<GetEnvHook> env_hooks_; + DISALLOW_COPY_AND_ASSIGN(JavaVMExt); }; |