-
-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathRuntime.h
135 lines (92 loc) · 4.36 KB
/
Runtime.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#ifndef RUNTIME_H_
#define RUNTIME_H_
#include "v8.h"
#include "JniLocalRef.h"
#include "ObjectManager.h"
#include "SimpleAllocator.h"
#include "WeakRef.h"
#include "ArrayBufferHelper.h"
#include "Profiler.h"
#include "ModuleInternal.h"
#include "MessageLoopTimer.h"
#include "File.h"
#include "Timers.h"
#include <mutex>
#include <android/looper.h>
#include <fcntl.h>
namespace tns {
class Runtime {
public:
enum IsolateData {
RUNTIME = 0,
CONSTANTS = 1
};
~Runtime();
static Runtime* GetRuntime(int runtimeId);
static Runtime* GetRuntime(v8::Isolate* isolate);
static Runtime* GetRuntimeFromIsolateData(v8::Isolate* isolate);
static ObjectManager* GetObjectManager(v8::Isolate* isolate);
static void Init(JavaVM* vm, void* reserved);
static void Init(JNIEnv* _env, jobject obj, int runtimeId, jstring filesPath, jstring nativeLibsDir, jboolean verboseLoggingEnabled, jboolean isDebuggable, jstring packageName, jobjectArray args, jstring callingDir, int maxLogcatObjectSize,
bool forceLog);
static void SetManualInstrumentationMode(jstring mode);
void Init(JNIEnv* env, jstring filesPath, jstring nativeLibsDir, bool verboseLoggingEnabled, bool isDebuggable, jstring packageName, jobjectArray args, jstring callingDir, int maxLogcatObjectSize, bool forceLog);
v8::Isolate* GetIsolate() const;
jobject GetJavaRuntime() const;
ObjectManager* GetObjectManager() const;
void RunModule(JNIEnv* _env, jobject obj, jstring scriptFile);
void RunWorker(jstring scriptFile);
jobject RunScript(JNIEnv* _env, jobject obj, jstring scriptFile);
jobject CallJSMethodNative(JNIEnv* _env, jobject obj, jint javaObjectID, jstring methodName, jint retType, jboolean isConstructor, jobjectArray packagedArgs);
void CreateJSInstanceNative(JNIEnv* _env, jobject obj, jobject javaObject, jint javaObjectID, jstring className);
jint GenerateNewObjectId(JNIEnv* env, jobject obj);
void AdjustAmountOfExternalAllocatedMemory();
bool NotifyGC(JNIEnv* env, jobject obj);
bool TryCallGC();
void PassExceptionToJsNative(JNIEnv* env, jobject obj, jthrowable exception, jstring message, jstring fullStackTrace, jstring jsStackTrace, jboolean isDiscarded);
void PassUncaughtExceptionFromWorkerToMainHandler(v8::Local<v8::String> message, v8::Local<v8::String> stackTrace, v8::Local<v8::String> filename, int lineno);
void DestroyRuntime();
void Lock();
void Unlock();
int GetId();
v8::Local<v8::Context> GetContext();
static v8::Platform* platform;
std::string ReadFileText(const std::string& filePath);
static int GetWriter();
static int GetReader();
static ALooper* GetMainLooper() {
return m_mainLooper;
}
private:
Runtime(JNIEnv* env, jobject runtime, int id);
int m_id;
jobject m_runtime;
v8::Isolate* m_isolate;
ObjectManager* m_objectManager;
ModuleInternal m_module;
ArrayBufferHelper m_arrayBufferHelper;
WeakRef m_weakRef;
Profiler m_profiler;
MessageLoopTimer* m_loopTimer;
int64_t m_lastUsedMemory;
v8::Persistent<v8::Function>* m_gcFunc;
volatile bool m_runGC;
v8::Persistent<v8::Context>* m_context;
bool m_isMainThread;
v8::Isolate* PrepareV8Runtime(const std::string& filesPath, const std::string& nativeLibsDir, const std::string& packageName, bool isDebuggable, const std::string& callingDir, const std::string& profilerOutputDir, const int maxLogcatObjectSize, const bool forceLog);
jobject ConvertJsValueToJavaObject(JEnv& env, const v8::Local<v8::Value>& value, int classReturnType);
static int GetAndroidVersion();
static int m_androidVersion;
static robin_hood::unordered_map<int, Runtime*> s_id2RuntimeCache;
static robin_hood::unordered_map<v8::Isolate*, Runtime*> s_isolate2RuntimesCache;
static JavaVM* s_jvm;
static jmethodID GET_USED_MEMORY_METHOD_ID;
static bool s_mainThreadInitialized;
static ALooper* m_mainLooper;
static int m_mainLooper_fd[2];
#ifdef APPLICATION_IN_DEBUG
std::mutex m_fileWriteMutex;
#endif
};
}
#endif /*#ifndef RUNTIME_H_*/