blob: dbb2674e0ba7d150136fab6095e6ba56862f31d6 [file] [log] [blame]
Ian Rogersdf20fe02011-07-20 20:34:16 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07003#include "jni_internal.h"
Carl Shapiro2ed144c2011-07-26 16:52:08 -07004
Carl Shapiro9b9ba282011-08-14 15:30:39 -07005#include <cstdarg>
Elliott Hughes0af55432011-08-17 18:37:28 -07006#include <dlfcn.h>
Carl Shapiro9b9ba282011-08-14 15:30:39 -07007#include <sys/mman.h>
Elliott Hughes0af55432011-08-17 18:37:28 -07008#include <utility>
9#include <vector>
Carl Shapiro2ed144c2011-07-26 16:52:08 -070010
Elliott Hughes18c07532011-08-18 15:50:51 -070011#include "assembler.h"
Elliott Hughes40ef99e2011-08-11 17:44:34 -070012#include "class_linker.h"
Carl Shapiroea4dca82011-08-01 13:45:38 -070013#include "jni.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070014#include "logging.h"
Carl Shapiro9b9ba282011-08-14 15:30:39 -070015#include "object.h"
Carl Shapiro2ed144c2011-07-26 16:52:08 -070016#include "runtime.h"
Carl Shapirofc322c72011-07-27 00:20:01 -070017#include "scoped_ptr.h"
18#include "stringpiece.h"
Carl Shapiro2ed144c2011-07-26 16:52:08 -070019#include "thread.h"
Ian Rogersdf20fe02011-07-20 20:34:16 -070020
21namespace art {
22
Elliott Hughescdf53122011-08-19 15:46:09 -070023// This is private API, but with two different implementations: ARM and x86.
24void CreateInvokeStub(Assembler* assembler, Method* method);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -070025
Elliott Hughescdf53122011-08-19 15:46:09 -070026// TODO: this should be in our anonymous namespace, but is currently needed
27// for testing in "jni_internal_test.cc".
28bool EnsureInvokeStub(Method* method) {
29 if (method->GetInvokeStub() != NULL) {
30 return true;
31 }
32 // TODO: use signature to find a matching stub
33 // TODO: failed, acquire a lock on the stub table
34 Assembler assembler;
35 CreateInvokeStub(&assembler, method);
36 // TODO: store native_entry in the stub table
37 int prot = PROT_READ | PROT_WRITE | PROT_EXEC;
38 size_t length = assembler.CodeSize();
39 void* addr = mmap(NULL, length, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
40 if (addr == MAP_FAILED) {
41 PLOG(FATAL) << "mmap failed";
42 }
43 MemoryRegion region(addr, length);
44 assembler.FinalizeInstructions(region);
45 method->SetInvokeStub(reinterpret_cast<Method::InvokeStub*>(region.pointer()));
46 return true;
47}
Elliott Hughes0af55432011-08-17 18:37:28 -070048
Elliott Hughescdf53122011-08-19 15:46:09 -070049// TODO: this can't be in our anonymous namespace because of the map in JavaVM.
50class SharedLibrary {
51public:
52 SharedLibrary(const std::string& path, void* handle, Object* class_loader)
53 : path_(path),
54 handle_(handle),
55 jni_on_load_lock_(Mutex::Create("JNI_OnLoad lock")),
56 jni_on_load_tid_(Thread::Current()->GetId()),
57 jni_on_load_result_(kPending) {
Elliott Hughes18c07532011-08-18 15:50:51 -070058 }
59
60 ~SharedLibrary() {
Elliott Hughescdf53122011-08-19 15:46:09 -070061 delete jni_on_load_lock_;
Elliott Hughes0af55432011-08-17 18:37:28 -070062 }
63
Elliott Hughescdf53122011-08-19 15:46:09 -070064 Object* GetClassLoader() {
65 return class_loader_;
Elliott Hughes0af55432011-08-17 18:37:28 -070066 }
67
Elliott Hughescdf53122011-08-19 15:46:09 -070068 /*
69 * Check the result of an earlier call to JNI_OnLoad on this library. If
70 * the call has not yet finished in another thread, wait for it.
71 */
72 bool CheckOnLoadResult(JavaVMExt* vm) {
73 Thread* self = Thread::Current();
74 if (jni_on_load_tid_ == self->GetId()) {
75 // Check this so we don't end up waiting for ourselves. We need
76 // to return "true" so the caller can continue.
77 LOG(INFO) << *self << " recursive attempt to load library "
78 << "\"" << path_ << "\"";
79 return true;
Elliott Hughes0af55432011-08-17 18:37:28 -070080 }
81
Elliott Hughescdf53122011-08-19 15:46:09 -070082 UNIMPLEMENTED(ERROR) << "need to pthread_cond_wait!";
83 // MutexLock mu(jni_on_load_lock_);
84 while (jni_on_load_result_ == kPending) {
85 if (vm->verbose_jni) {
86 LOG(INFO) << "[" << *self << " waiting for \"" << path_ << "\" "
87 << "JNI_OnLoad...]";
Elliott Hughes0af55432011-08-17 18:37:28 -070088 }
Elliott Hughescdf53122011-08-19 15:46:09 -070089 Thread::State old_state = self->GetState();
90 self->SetState(Thread::kWaiting); // TODO: VMWAIT
91 // pthread_cond_wait(&jni_on_load_cond_, &jni_on_load_lock_);
Elliott Hughes0af55432011-08-17 18:37:28 -070092 self->SetState(old_state);
Elliott Hughes0af55432011-08-17 18:37:28 -070093 }
94
Elliott Hughescdf53122011-08-19 15:46:09 -070095 bool okay = (jni_on_load_result_ == kOkay);
96 if (vm->verbose_jni) {
97 LOG(INFO) << "[Earlier JNI_OnLoad for \"" << path_ << "\" "
98 << (okay ? "succeeded" : "failed") << "]";
99 }
100 return okay;
101 }
102
103 void SetResult(bool result) {
104 jni_on_load_result_ = result ? kOkay : kFailed;
105 jni_on_load_tid_ = 0;
Elliott Hughes0af55432011-08-17 18:37:28 -0700106
107 // Broadcast a wakeup to anybody sleeping on the condition variable.
108 UNIMPLEMENTED(ERROR) << "missing pthread_cond_broadcast";
Elliott Hughescdf53122011-08-19 15:46:09 -0700109 // MutexLock mu(library->jni_on_load_lock_);
110 // pthread_cond_broadcast(&library->jni_on_load_cond_);
Elliott Hughes0af55432011-08-17 18:37:28 -0700111 }
Elliott Hughescdf53122011-08-19 15:46:09 -0700112
113 private:
114 enum JNI_OnLoadState {
115 kPending,
116 kFailed,
117 kOkay,
118 };
119
120 // Path to library "/system/lib/libjni.so".
121 std::string path_;
122
123 // The void* returned by dlopen(3).
124 void* handle_;
125
126 // The ClassLoader this library is associated with.
127 Object* class_loader_;
128
129 // Guards remaining items.
130 Mutex* jni_on_load_lock_;
131 // Wait for JNI_OnLoad in other thread.
132 pthread_cond_t jni_on_load_cond_;
133 // Recursive invocation guard.
134 uint32_t jni_on_load_tid_;
135 // Result of earlier JNI_OnLoad call.
136 JNI_OnLoadState jni_on_load_result_;
137};
138
139namespace {
Elliott Hughes0af55432011-08-17 18:37:28 -0700140
Elliott Hughes22f40932011-08-12 13:06:37 -0700141// Entry/exit processing for all JNI calls.
142//
143// This performs the necessary thread state switching, lets us amortize the
144// cost of working out the current thread, and lets us check (and repair) apps
145// that are using a JNIEnv on the wrong thread.
146class ScopedJniThreadState {
147 public:
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700148 explicit ScopedJniThreadState(JNIEnv* env)
149 : env_(reinterpret_cast<JNIEnvExt*>(env)) {
Elliott Hughesb20a5542011-08-12 18:03:12 -0700150 self_ = ThreadForEnv(env);
Elliott Hughes22f40932011-08-12 13:06:37 -0700151 self_->SetState(Thread::kRunnable);
152 }
153
154 ~ScopedJniThreadState() {
155 self_->SetState(Thread::kNative);
156 }
157
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700158 JNIEnvExt* Env() {
159 return env_;
160 }
161
Elliott Hughesb20a5542011-08-12 18:03:12 -0700162 Thread* Self() {
Elliott Hughes22f40932011-08-12 13:06:37 -0700163 return self_;
164 }
165
Elliott Hughesb20a5542011-08-12 18:03:12 -0700166 private:
167 static Thread* ThreadForEnv(JNIEnv* env) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700168 // TODO: need replacement for gDvmJni.
169 bool workAroundAppJniBugs = true;
170 Thread* env_self = reinterpret_cast<JNIEnvExt*>(env)->self;
171 Thread* self = workAroundAppJniBugs ? Thread::Current() : env_self;
172 if (self != env_self) {
Elliott Hughes330304d2011-08-12 14:28:05 -0700173 LOG(ERROR) << "JNI ERROR: JNIEnv for " << *env_self
174 << " used on " << *self;
175 // TODO: dump stack
Elliott Hughes22f40932011-08-12 13:06:37 -0700176 }
177 return self;
178 }
179
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700180 JNIEnvExt* env_;
Elliott Hughes22f40932011-08-12 13:06:37 -0700181 Thread* self_;
182 DISALLOW_COPY_AND_ASSIGN(ScopedJniThreadState);
183};
184
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700185/*
186 * Add a local reference for an object to the current stack frame. When
187 * the native function returns, the reference will be discarded.
188 *
189 * We need to allow the same reference to be added multiple times.
190 *
191 * This will be called on otherwise unreferenced objects. We cannot do
192 * GC allocations here, and it's best if we don't grab a mutex.
193 *
194 * Returns the local reference (currently just the same pointer that was
195 * passed in), or NULL on failure.
196 */
Elliott Hughes8a26c5c2011-08-15 18:35:43 -0700197template<typename T>
198T AddLocalReference(ScopedJniThreadState& ts, Object* obj) {
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700199 if (obj == NULL) {
200 return NULL;
201 }
202
203 IndirectReferenceTable& locals = ts.Env()->locals;
204
205 uint32_t cookie = IRT_FIRST_SEGMENT; // TODO
206 IndirectRef ref = locals.Add(cookie, obj);
207 if (ref == NULL) {
208 // TODO: just change Add's DCHECK to CHECK and lose this?
209 locals.Dump();
210 LOG(FATAL) << "Failed adding to JNI local reference table "
211 << "(has " << locals.Capacity() << " entries)";
212 // TODO: dvmDumpThread(dvmThreadSelf(), false);
213 }
214
215#if 0 // TODO: fix this to understand PushLocalFrame, so we can turn it on.
216 if (ts.Env()->check_jni) {
217 size_t entry_count = locals.Capacity();
218 if (entry_count > 16) {
219 std::string class_name(PrettyDescriptor(obj->GetClass()->GetDescriptor()));
220 LOG(WARNING) << "Warning: more than 16 JNI local references: "
221 << entry_count << " (most recent was a " << class_name << ")";
222 locals.Dump();
223 // TODO: dvmDumpThread(dvmThreadSelf(), false);
224 // dvmAbort();
225 }
226 }
227#endif
228
229 if (false /*gDvmJni.workAroundAppJniBugs*/) { // TODO
230 // Hand out direct pointers to support broken old apps.
231 return reinterpret_cast<T>(obj);
232 }
233
234 return reinterpret_cast<T>(ref);
235}
236
Elliott Hughescdf53122011-08-19 15:46:09 -0700237jweak AddWeakGlobalReference(ScopedJniThreadState& ts, Object* obj) {
238 if (obj == NULL) {
239 return NULL;
240 }
241 JavaVMExt* vm = Runtime::Current()->GetJavaVM();
242 IndirectReferenceTable& weak_globals = vm->weak_globals;
243 MutexLock mu(vm->weak_globals_lock);
244 IndirectRef ref = weak_globals.Add(IRT_FIRST_SEGMENT, obj);
245 return reinterpret_cast<jweak>(ref);
246}
247
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700248template<typename T>
249T Decode(ScopedJniThreadState& ts, jobject obj) {
250 if (obj == NULL) {
251 return NULL;
252 }
253
254 IndirectRef ref = reinterpret_cast<IndirectRef>(obj);
255 IndirectRefKind kind = GetIndirectRefKind(ref);
256 Object* result;
257 switch (kind) {
258 case kLocal:
259 {
260 IndirectReferenceTable& locals = ts.Env()->locals;
261 result = locals.Get(ref);
262 break;
263 }
264 case kGlobal:
265 {
266 JavaVMExt* vm = Runtime::Current()->GetJavaVM();
267 IndirectReferenceTable& globals = vm->globals;
Elliott Hughes18c07532011-08-18 15:50:51 -0700268 MutexLock mu(vm->globals_lock);
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700269 result = globals.Get(ref);
270 break;
271 }
272 case kWeakGlobal:
273 {
274 JavaVMExt* vm = Runtime::Current()->GetJavaVM();
275 IndirectReferenceTable& weak_globals = vm->weak_globals;
Elliott Hughes18c07532011-08-18 15:50:51 -0700276 MutexLock mu(vm->weak_globals_lock);
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700277 result = weak_globals.Get(ref);
278 if (result == kClearedJniWeakGlobal) {
279 // This is a special case where it's okay to return NULL.
280 return NULL;
281 }
282 break;
283 }
284 case kInvalid:
285 default:
286 if (false /*gDvmJni.workAroundAppJniBugs*/) { // TODO
287 // Assume an invalid local reference is actually a direct pointer.
288 return reinterpret_cast<T>(obj);
289 }
290 LOG(FATAL) << "Invalid indirect reference " << obj;
291 return reinterpret_cast<T>(kInvalidIndirectRefObject);
292 }
293
294 if (result == NULL) {
295 LOG(FATAL) << "JNI ERROR (app bug): use of deleted " << kind << ": "
296 << obj;
297 }
298 return reinterpret_cast<T>(result);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -0700299}
300
Elliott Hughescdf53122011-08-19 15:46:09 -0700301Field* DecodeField(ScopedJniThreadState& ts, jfieldID fid) {
302 return Decode<Field*>(ts, reinterpret_cast<jweak>(fid));
303}
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700304
Elliott Hughescdf53122011-08-19 15:46:09 -0700305Method* DecodeMethod(ScopedJniThreadState& ts, jmethodID mid) {
306 return Decode<Method*>(ts, reinterpret_cast<jweak>(mid));
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700307}
308
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700309byte* CreateArgArray(ScopedJniThreadState& ts, Method* method, va_list ap) {
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700310 size_t num_bytes = method->NumArgArrayBytes();
311 scoped_array<byte> arg_array(new byte[num_bytes]);
312 const StringPiece& shorty = method->GetShorty();
Ian Rogers4dd71f12011-08-16 14:16:02 -0700313 for (int i = 1, offset = 0; i < shorty.size(); ++i) {
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700314 switch (shorty[i]) {
315 case 'Z':
316 case 'B':
317 case 'C':
318 case 'S':
319 case 'I':
320 *reinterpret_cast<int32_t*>(&arg_array[offset]) = va_arg(ap, jint);
321 offset += 4;
322 break;
323 case 'F':
324 *reinterpret_cast<float*>(&arg_array[offset]) = va_arg(ap, jdouble);
325 offset += 4;
326 break;
327 case 'L': {
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700328 Object* obj = Decode<Object*>(ts, va_arg(ap, jobject));
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700329 *reinterpret_cast<Object**>(&arg_array[offset]) = obj;
330 offset += sizeof(Object*);
331 break;
332 }
333 case 'D':
334 *reinterpret_cast<double*>(&arg_array[offset]) = va_arg(ap, jdouble);
335 offset += 8;
336 break;
337 case 'J':
338 *reinterpret_cast<int64_t*>(&arg_array[offset]) = va_arg(ap, jlong);
339 offset += 8;
340 break;
341 }
342 }
343 return arg_array.release();
344}
345
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700346byte* CreateArgArray(ScopedJniThreadState& ts, Method* method, jvalue* args) {
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700347 size_t num_bytes = method->NumArgArrayBytes();
348 scoped_array<byte> arg_array(new byte[num_bytes]);
349 const StringPiece& shorty = method->GetShorty();
Ian Rogers4dd71f12011-08-16 14:16:02 -0700350 for (int i = 1, offset = 0; i < shorty.size(); ++i) {
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700351 switch (shorty[i]) {
352 case 'Z':
353 case 'B':
354 case 'C':
355 case 'S':
356 case 'I':
357 *reinterpret_cast<uint32_t*>(&arg_array[offset]) = args[i - 1].i;
358 offset += 4;
359 break;
360 case 'F':
361 *reinterpret_cast<float*>(&arg_array[offset]) = args[i - 1].f;
362 offset += 4;
363 break;
364 case 'L': {
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700365 Object* obj = Decode<Object*>(ts, args[i - 1].l);
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700366 *reinterpret_cast<Object**>(&arg_array[offset]) = obj;
367 offset += sizeof(Object*);
368 break;
369 }
370 case 'D':
371 *reinterpret_cast<double*>(&arg_array[offset]) = args[i - 1].d;
372 offset += 8;
373 break;
374 case 'J':
375 *reinterpret_cast<uint64_t*>(&arg_array[offset]) = args[i - 1].j;
376 offset += 8;
377 break;
378 }
379 }
380 return arg_array.release();
381}
382
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700383JValue InvokeWithArgArray(ScopedJniThreadState& ts, jobject obj,
Elliott Hughescdf53122011-08-19 15:46:09 -0700384 jmethodID mid, byte* args) {
385 Method* method = DecodeMethod(ts, mid);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700386 Object* rcvr = Decode<Object*>(ts, obj);
Ian Rogers6de08602011-08-19 14:52:39 -0700387 Thread* self = ts.Self();
388
389 // Push a transition back into managed code onto the linked list in thread
390 CHECK_EQ(Thread::kRunnable, self->GetState());
391 NativeToManagedRecord record;
392 self->PushNativeToManagedRecord(&record);
393
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700394 // Call the invoke stub associated with the method
395 // Pass everything as arguments
396 const Method::InvokeStub* stub = method->GetInvokeStub();
397 CHECK(stub != NULL);
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700398 JValue result;
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700399 // TODO: we should always have code associated with a method
400 if (method->GetCode()) {
Ian Rogers6de08602011-08-19 14:52:39 -0700401 (*stub)(method, rcvr, self, args, &result);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700402 } else {
403 // TODO: pretty print method here
404 LOG(WARNING) << "Not invoking method with no associated code";
405 result.j = 0;
406 }
Ian Rogers6de08602011-08-19 14:52:39 -0700407 // Pop transition
408 self->PopNativeToManagedRecord(record);
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700409 return result;
410}
411
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700412JValue InvokeWithJValues(ScopedJniThreadState& ts, jobject obj,
Elliott Hughescdf53122011-08-19 15:46:09 -0700413 jmethodID mid, jvalue* args) {
414 Method* method = DecodeMethod(ts, mid);
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700415 scoped_array<byte> arg_array(CreateArgArray(ts, method, args));
Elliott Hughescdf53122011-08-19 15:46:09 -0700416 return InvokeWithArgArray(ts, obj, mid, arg_array.get());
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700417}
418
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700419JValue InvokeWithVarArgs(ScopedJniThreadState& ts, jobject obj,
Elliott Hughescdf53122011-08-19 15:46:09 -0700420 jmethodID mid, va_list args) {
421 Method* method = DecodeMethod(ts, mid);
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700422 scoped_array<byte> arg_array(CreateArgArray(ts, method, args));
Elliott Hughescdf53122011-08-19 15:46:09 -0700423 return InvokeWithArgArray(ts, obj, mid, arg_array.get());
Carl Shapiroea4dca82011-08-01 13:45:38 -0700424}
425
Elliott Hughes6b436852011-08-12 10:16:44 -0700426// Section 12.3.2 of the JNI spec describes JNI class descriptors. They're
427// separated with slashes but aren't wrapped with "L;" like regular descriptors
428// (i.e. "a/b/C" rather than "La/b/C;"). Arrays of reference types are an
429// exception; there the "L;" must be present ("[La/b/C;"). Historically we've
430// supported names with dots too (such as "a.b.C").
431std::string NormalizeJniClassDescriptor(const char* name) {
432 std::string result;
433 // Add the missing "L;" if necessary.
434 if (name[0] == '[') {
435 result = name;
436 } else {
437 result += 'L';
438 result += name;
439 result += ';';
440 }
441 // Rewrite '.' as '/' for backwards compatibility.
Elliott Hughesa5b897e2011-08-16 11:33:06 -0700442 if (result.find('.') != std::string::npos) {
443 LOG(WARNING) << "Call to JNI FindClass with dots in name: "
444 << "\"" << name << "\"";
445 std::replace(result.begin(), result.end(), '.', '/');
Elliott Hughes6b436852011-08-12 10:16:44 -0700446 }
447 return result;
448}
449
Elliott Hughescdf53122011-08-19 15:46:09 -0700450jmethodID FindMethodID(ScopedJniThreadState& ts, jclass jni_class, const char* name, const char* sig, bool is_static) {
451 Class* c = Decode<Class*>(ts, jni_class);
452 if (!c->IsInitialized()) {
Carl Shapiro83ab4f32011-08-15 20:21:39 -0700453 // TODO: initialize the class
454 }
Elliott Hughescdf53122011-08-19 15:46:09 -0700455
456 Method* method = NULL;
457 if (is_static) {
458 method = c->FindDirectMethod(name, sig);
Ian Rogers4dd71f12011-08-16 14:16:02 -0700459 } else {
Elliott Hughescdf53122011-08-19 15:46:09 -0700460 method = c->FindVirtualMethod(name, sig);
461 if (method == NULL) {
462 // No virtual method matching the signature. Search declared
463 // private methods and constructors.
464 method = c->FindDeclaredDirectMethod(name, sig);
Ian Rogers4dd71f12011-08-16 14:16:02 -0700465 }
Carl Shapiro83ab4f32011-08-15 20:21:39 -0700466 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700467
Elliott Hughescdf53122011-08-19 15:46:09 -0700468 if (method == NULL || method->IsStatic() != is_static) {
469 Thread* self = Thread::Current();
470 std::string class_name(c->GetDescriptor().ToString());
471 // TODO: try searching for the opposite kind of method from is_static
472 // for better diagnostics?
473 self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
474 "no %s method \"%s.%s%s\"", is_static ? "static" : "non-static",
475 class_name.c_str(), name, sig);
476 return NULL;
477 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700478
Elliott Hughescdf53122011-08-19 15:46:09 -0700479 bool success = EnsureInvokeStub(method);
480 if (!success) {
481 // TODO: throw OutOfMemoryException
482 return NULL;
483 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700484
Elliott Hughescdf53122011-08-19 15:46:09 -0700485 return reinterpret_cast<jmethodID>(AddWeakGlobalReference(ts, method));
Carl Shapiroea4dca82011-08-01 13:45:38 -0700486}
487
Elliott Hughescdf53122011-08-19 15:46:09 -0700488jfieldID FindFieldID(ScopedJniThreadState& ts, jclass jni_class, const char* name, const char* sig, bool is_static) {
489 Class* c = Decode<Class*>(ts, jni_class);
490 if (!c->IsInitialized()) {
Carl Shapiro83ab4f32011-08-15 20:21:39 -0700491 // TODO: initialize the class
492 }
Elliott Hughescdf53122011-08-19 15:46:09 -0700493
494 Field* field = NULL;
495 if (is_static) {
496 field = c->FindStaticField(name, sig);
Ian Rogers4dd71f12011-08-16 14:16:02 -0700497 } else {
Elliott Hughescdf53122011-08-19 15:46:09 -0700498 field = c->FindInstanceField(name, sig);
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700499 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700500
Elliott Hughescdf53122011-08-19 15:46:09 -0700501 if (field == NULL) {
502 Thread* self = Thread::Current();
503 std::string class_name(c->GetDescriptor().ToString());
504 self->ThrowNewException("Ljava/lang/NoSuchFieldError;",
505 "no \"%s\" field \"%s\" in class \"%s\" or its superclasses", sig,
506 name, class_name.c_str());
Elliott Hughes8a26c5c2011-08-15 18:35:43 -0700507 return NULL;
508 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700509
Elliott Hughescdf53122011-08-19 15:46:09 -0700510 jweak fid = AddWeakGlobalReference(ts, field);
511 return reinterpret_cast<jfieldID>(fid);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700512}
513
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700514template<typename JniT, typename ArtT>
515JniT NewPrimitiveArray(ScopedJniThreadState& ts, jsize length) {
516 CHECK_GE(length, 0); // TODO: ReportJniError
517 ArtT* result = ArtT::Alloc(length);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -0700518 return AddLocalReference<JniT>(ts, result);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700519}
520
Elliott Hughescdf53122011-08-19 15:46:09 -0700521} // namespace
Carl Shapiroea4dca82011-08-01 13:45:38 -0700522
Elliott Hughescdf53122011-08-19 15:46:09 -0700523class JNI {
524 public:
Carl Shapiroea4dca82011-08-01 13:45:38 -0700525
Elliott Hughescdf53122011-08-19 15:46:09 -0700526 static jint GetVersion(JNIEnv* env) {
527 ScopedJniThreadState ts(env);
528 return JNI_VERSION_1_6;
529 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700530
Elliott Hughescdf53122011-08-19 15:46:09 -0700531 static jclass DefineClass(JNIEnv* env, const char*, jobject, const jbyte*, jsize) {
532 ScopedJniThreadState ts(env);
533 LOG(WARNING) << "JNI DefineClass is not supported";
Elliott Hughesf2682d52011-08-15 16:37:04 -0700534 return NULL;
535 }
536
Elliott Hughescdf53122011-08-19 15:46:09 -0700537 static jclass FindClass(JNIEnv* env, const char* name) {
538 ScopedJniThreadState ts(env);
539 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
540 std::string descriptor(NormalizeJniClassDescriptor(name));
541 // TODO: need to get the appropriate ClassLoader.
542 Class* c = class_linker->FindClass(descriptor, NULL);
543 return AddLocalReference<jclass>(ts, c);
Ian Rogers4dd71f12011-08-16 14:16:02 -0700544 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700545
Elliott Hughescdf53122011-08-19 15:46:09 -0700546 static jmethodID FromReflectedMethod(JNIEnv* env, jobject java_method) {
547 ScopedJniThreadState ts(env);
548 Method* method = Decode<Method*>(ts, java_method);
549 return reinterpret_cast<jmethodID>(AddWeakGlobalReference(ts, method));
Elliott Hughesf2682d52011-08-15 16:37:04 -0700550 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700551
Elliott Hughescdf53122011-08-19 15:46:09 -0700552 static jfieldID FromReflectedField(JNIEnv* env, jobject java_field) {
553 ScopedJniThreadState ts(env);
554 Field* field = Decode<Field*>(ts, java_field);
555 return reinterpret_cast<jfieldID>(AddWeakGlobalReference(ts, field));
556 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700557
Elliott Hughescdf53122011-08-19 15:46:09 -0700558 static jobject ToReflectedMethod(JNIEnv* env, jclass, jmethodID mid, jboolean) {
559 ScopedJniThreadState ts(env);
560 Method* method = DecodeMethod(ts, mid);
561 return AddLocalReference<jobject>(ts, method);
562 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700563
Elliott Hughescdf53122011-08-19 15:46:09 -0700564 static jobject ToReflectedField(JNIEnv* env, jclass, jfieldID fid, jboolean) {
565 ScopedJniThreadState ts(env);
566 Field* field = DecodeField(ts, fid);
567 return AddLocalReference<jobject>(ts, field);
568 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700569
Elliott Hughescdf53122011-08-19 15:46:09 -0700570 static jclass GetSuperclass(JNIEnv* env, jclass sub) {
571 ScopedJniThreadState ts(env);
572 UNIMPLEMENTED(FATAL);
573 return NULL;
574 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700575
Elliott Hughescdf53122011-08-19 15:46:09 -0700576 static jboolean IsAssignableFrom(JNIEnv* env, jclass sub, jclass sup) {
577 ScopedJniThreadState ts(env);
578 UNIMPLEMENTED(FATAL);
579 return JNI_FALSE;
580 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700581
Elliott Hughescdf53122011-08-19 15:46:09 -0700582 static jint Throw(JNIEnv* env, jthrowable obj) {
583 ScopedJniThreadState ts(env);
584 UNIMPLEMENTED(FATAL);
585 return 0;
586 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700587
Elliott Hughescdf53122011-08-19 15:46:09 -0700588 static jint ThrowNew(JNIEnv* env, jclass clazz, const char* msg) {
589 ScopedJniThreadState ts(env);
590 UNIMPLEMENTED(FATAL);
591 return 0;
592 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700593
Elliott Hughescdf53122011-08-19 15:46:09 -0700594 static jthrowable ExceptionOccurred(JNIEnv* env) {
595 ScopedJniThreadState ts(env);
596 Object* exception = ts.Self()->GetException();
597 if (exception == NULL) {
598 return NULL;
599 } else {
600 // TODO: if adding a local reference failing causes the VM to abort
601 // then the following check will never occur.
602 jthrowable localException = AddLocalReference<jthrowable>(ts, exception);
603 if (localException == NULL) {
604 // We were unable to add a new local reference, and threw a new
605 // exception. We can't return "exception", because it's not a
606 // local reference. So we have to return NULL, indicating that
607 // there was no exception, even though it's pretty much raining
608 // exceptions in here.
609 LOG(WARNING) << "JNI WARNING: addLocal/exception combo";
610 }
611 return localException;
612 }
613 }
614
615 static void ExceptionDescribe(JNIEnv* env) {
616 ScopedJniThreadState ts(env);
617 UNIMPLEMENTED(FATAL);
618 }
619
620 static void ExceptionClear(JNIEnv* env) {
621 ScopedJniThreadState ts(env);
622 ts.Self()->ClearException();
623 }
624
625 static void FatalError(JNIEnv* env, const char* msg) {
626 ScopedJniThreadState ts(env);
627 LOG(FATAL) << "JNI FatalError called: " << msg;
628 }
629
630 static jint PushLocalFrame(JNIEnv* env, jint cap) {
631 ScopedJniThreadState ts(env);
632 UNIMPLEMENTED(WARNING) << "ignoring PushLocalFrame(" << cap << ")";
633 return JNI_OK;
634 }
635
636 static jobject PopLocalFrame(JNIEnv* env, jobject res) {
637 ScopedJniThreadState ts(env);
638 UNIMPLEMENTED(WARNING) << "ignoring PopLocalFrame " << res;
639 return res;
640 }
641
642 static jobject NewGlobalRef(JNIEnv* env, jobject obj) {
643 ScopedJniThreadState ts(env);
644 if (obj == NULL) {
645 return NULL;
646 }
647
648 JavaVMExt* vm = Runtime::Current()->GetJavaVM();
649 IndirectReferenceTable& globals = vm->globals;
650 MutexLock mu(vm->globals_lock);
651 IndirectRef ref = globals.Add(IRT_FIRST_SEGMENT, Decode<Object*>(ts, obj));
652 return reinterpret_cast<jobject>(ref);
653 }
654
655 static void DeleteGlobalRef(JNIEnv* env, jobject obj) {
656 ScopedJniThreadState ts(env);
657 if (obj == NULL) {
658 return;
659 }
660
661 JavaVMExt* vm = Runtime::Current()->GetJavaVM();
662 IndirectReferenceTable& globals = vm->globals;
663 MutexLock mu(vm->globals_lock);
664
665 if (!globals.Remove(IRT_FIRST_SEGMENT, obj)) {
666 LOG(WARNING) << "JNI WARNING: DeleteGlobalRef(" << obj << ") "
667 << "failed to find entry";
668 }
669 }
670
671 static jweak NewWeakGlobalRef(JNIEnv* env, jobject obj) {
672 ScopedJniThreadState ts(env);
673 return AddWeakGlobalReference(ts, Decode<Object*>(ts, obj));
674 }
675
676 static void DeleteWeakGlobalRef(JNIEnv* env, jweak obj) {
677 ScopedJniThreadState ts(env);
678 if (obj == NULL) {
679 return;
680 }
681
682 JavaVMExt* vm = Runtime::Current()->GetJavaVM();
683 IndirectReferenceTable& weak_globals = vm->weak_globals;
684 MutexLock mu(vm->weak_globals_lock);
685
686 if (!weak_globals.Remove(IRT_FIRST_SEGMENT, obj)) {
687 LOG(WARNING) << "JNI WARNING: DeleteWeakGlobalRef(" << obj << ") "
688 << "failed to find entry";
689 }
690 }
691
692 static jobject NewLocalRef(JNIEnv* env, jobject obj) {
693 ScopedJniThreadState ts(env);
694 if (obj == NULL) {
695 return NULL;
696 }
697
698 IndirectReferenceTable& locals = ts.Env()->locals;
699
700 uint32_t cookie = IRT_FIRST_SEGMENT; // TODO
701 IndirectRef ref = locals.Add(cookie, Decode<Object*>(ts, obj));
702 return reinterpret_cast<jobject>(ref);
703 }
704
705 static void DeleteLocalRef(JNIEnv* env, jobject obj) {
706 ScopedJniThreadState ts(env);
707 if (obj == NULL) {
708 return;
709 }
710
711 IndirectReferenceTable& locals = ts.Env()->locals;
712
713 uint32_t cookie = IRT_FIRST_SEGMENT; // TODO
714 if (!locals.Remove(cookie, obj)) {
715 // Attempting to delete a local reference that is not in the
716 // topmost local reference frame is a no-op. DeleteLocalRef returns
717 // void and doesn't throw any exceptions, but we should probably
718 // complain about it so the user will notice that things aren't
719 // going quite the way they expect.
720 LOG(WARNING) << "JNI WARNING: DeleteLocalRef(" << obj << ") "
721 << "failed to find entry";
722 }
723 }
724
725 static jboolean IsSameObject(JNIEnv* env, jobject obj1, jobject obj2) {
726 ScopedJniThreadState ts(env);
727 return (Decode<Object*>(ts, obj1) == Decode<Object*>(ts, obj2))
728 ? JNI_TRUE : JNI_FALSE;
729 }
730
731 static jint EnsureLocalCapacity(JNIEnv* env, jint) {
732 ScopedJniThreadState ts(env);
733 UNIMPLEMENTED(FATAL);
734 return 0;
735 }
736
737 static jobject AllocObject(JNIEnv* env, jclass clazz) {
738 ScopedJniThreadState ts(env);
739 UNIMPLEMENTED(FATAL);
740 return NULL;
741 }
742
743 static jobject NewObject(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
744 ScopedJniThreadState ts(env);
745 va_list args;
746 va_start(args, methodID);
747 jobject result = NewObjectV(env, clazz, methodID, args);
748 va_end(args);
749 return result;
750 }
751
752 static jobject NewObjectV(JNIEnv* env,
753 jclass clazz, jmethodID methodID, va_list args) {
754 ScopedJniThreadState ts(env);
755 Class* klass = Decode<Class*>(ts, clazz);
756 Object* result = klass->NewInstance();
757 jobject local_result = AddLocalReference<jobject>(ts, result);
758 CallNonvirtualVoidMethodV(env, local_result, clazz, methodID, args);
759 return local_result;
760 }
761
762 static jobject NewObjectA(JNIEnv* env,
763 jclass clazz, jmethodID methodID, jvalue* args) {
764 ScopedJniThreadState ts(env);
765 Class* klass = Decode<Class*>(ts, clazz);
766 Object* result = klass->NewInstance();
767 jobject local_result = AddLocalReference<jobjectArray>(ts, result);
768 CallNonvirtualVoidMethodA(env, local_result, clazz, methodID, args);
769 return local_result;
770 }
771
772 static jclass GetObjectClass(JNIEnv* env, jobject obj) {
773 ScopedJniThreadState ts(env);
774 UNIMPLEMENTED(FATAL);
775 return NULL;
776 }
777
778 static jboolean IsInstanceOf(JNIEnv* env, jobject jobj, jclass clazz) {
779 ScopedJniThreadState ts(env);
780 CHECK_NE(static_cast<jclass>(NULL), clazz);
781 if (jobj == NULL) {
782 // NB. JNI is different from regular Java instanceof in this respect
783 return JNI_TRUE;
784 } else {
785 Object* obj = Decode<Object*>(ts, jobj);
786 Class* klass = Decode<Class*>(ts, clazz);
787 return Object::InstanceOf(obj, klass) ? JNI_TRUE : JNI_FALSE;
788 }
789 }
790
791 static jmethodID GetMethodID(JNIEnv* env, jclass c, const char* name, const char* sig) {
792 ScopedJniThreadState ts(env);
793 return FindMethodID(ts, c, name, sig, false);
794 }
795
796 static jmethodID GetStaticMethodID(JNIEnv* env, jclass c, const char* name, const char* sig) {
797 ScopedJniThreadState ts(env);
798 return FindMethodID(ts, c, name, sig, true);
799 }
800
801 static jobject CallObjectMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
802 ScopedJniThreadState ts(env);
803 UNIMPLEMENTED(FATAL);
804 return NULL;
805 }
806
807 static jobject CallObjectMethodV(JNIEnv* env,
808 jobject obj, jmethodID methodID, va_list args) {
809 ScopedJniThreadState ts(env);
810 UNIMPLEMENTED(FATAL);
811 return NULL;
812 }
813
814 static jobject CallObjectMethodA(JNIEnv* env,
815 jobject obj, jmethodID methodID, jvalue* args) {
816 ScopedJniThreadState ts(env);
817 UNIMPLEMENTED(FATAL);
818 return NULL;
819 }
820
821 static jboolean CallBooleanMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
822 ScopedJniThreadState ts(env);
823 UNIMPLEMENTED(FATAL);
824 return JNI_FALSE;
825 }
826
827 static jboolean CallBooleanMethodV(JNIEnv* env,
828 jobject obj, jmethodID methodID, va_list args) {
829 ScopedJniThreadState ts(env);
830 UNIMPLEMENTED(FATAL);
831 return JNI_FALSE;
832 }
833
834 static jboolean CallBooleanMethodA(JNIEnv* env,
835 jobject obj, jmethodID methodID, jvalue* args) {
836 ScopedJniThreadState ts(env);
837 UNIMPLEMENTED(FATAL);
838 return JNI_FALSE;
839 }
840
841 static jbyte CallByteMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
842 ScopedJniThreadState ts(env);
843 UNIMPLEMENTED(FATAL);
844 return 0;
845 }
846
847 static jbyte CallByteMethodV(JNIEnv* env,
848 jobject obj, jmethodID methodID, va_list args) {
849 ScopedJniThreadState ts(env);
850 UNIMPLEMENTED(FATAL);
851 return 0;
852 }
853
854 static jbyte CallByteMethodA(JNIEnv* env,
855 jobject obj, jmethodID methodID, jvalue* args) {
856 ScopedJniThreadState ts(env);
857 UNIMPLEMENTED(FATAL);
858 return 0;
859 }
860
861 static jchar CallCharMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
862 ScopedJniThreadState ts(env);
863 UNIMPLEMENTED(FATAL);
864 return 0;
865 }
866
867 static jchar CallCharMethodV(JNIEnv* env,
868 jobject obj, jmethodID methodID, va_list args) {
869 ScopedJniThreadState ts(env);
870 UNIMPLEMENTED(FATAL);
871 return 0;
872 }
873
874 static jchar CallCharMethodA(JNIEnv* env,
875 jobject obj, jmethodID methodID, jvalue* args) {
876 ScopedJniThreadState ts(env);
877 UNIMPLEMENTED(FATAL);
878 return 0;
879 }
880
881 static jshort CallShortMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
882 ScopedJniThreadState ts(env);
883 UNIMPLEMENTED(FATAL);
884 return 0;
885 }
886
887 static jshort CallShortMethodV(JNIEnv* env,
888 jobject obj, jmethodID methodID, va_list args) {
889 ScopedJniThreadState ts(env);
890 UNIMPLEMENTED(FATAL);
891 return 0;
892 }
893
894 static jshort CallShortMethodA(JNIEnv* env,
895 jobject obj, jmethodID methodID, jvalue* args) {
896 ScopedJniThreadState ts(env);
897 UNIMPLEMENTED(FATAL);
898 return 0;
899 }
900
901 static jint CallIntMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
902 ScopedJniThreadState ts(env);
903 UNIMPLEMENTED(FATAL);
904 return 0;
905 }
906
907 static jint CallIntMethodV(JNIEnv* env,
908 jobject obj, jmethodID methodID, va_list args) {
909 ScopedJniThreadState ts(env);
910 UNIMPLEMENTED(FATAL);
911 return 0;
912 }
913
914 static jint CallIntMethodA(JNIEnv* env,
915 jobject obj, jmethodID methodID, jvalue* args) {
916 ScopedJniThreadState ts(env);
917 UNIMPLEMENTED(FATAL);
918 return 0;
919 }
920
921 static jlong CallLongMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
922 ScopedJniThreadState ts(env);
923 UNIMPLEMENTED(FATAL);
924 return 0;
925 }
926
927 static jlong CallLongMethodV(JNIEnv* env,
928 jobject obj, jmethodID methodID, va_list args) {
929 ScopedJniThreadState ts(env);
930 UNIMPLEMENTED(FATAL);
931 return 0;
932 }
933
934 static jlong CallLongMethodA(JNIEnv* env,
935 jobject obj, jmethodID methodID, jvalue* args) {
936 ScopedJniThreadState ts(env);
937 UNIMPLEMENTED(FATAL);
938 return 0;
939 }
940
941 static jfloat CallFloatMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
942 ScopedJniThreadState ts(env);
943 UNIMPLEMENTED(FATAL);
944 return 0;
945 }
946
947 static jfloat CallFloatMethodV(JNIEnv* env,
948 jobject obj, jmethodID methodID, va_list args) {
949 ScopedJniThreadState ts(env);
950 UNIMPLEMENTED(FATAL);
951 return 0;
952 }
953
954 static jfloat CallFloatMethodA(JNIEnv* env,
955 jobject obj, jmethodID methodID, jvalue* args) {
956 ScopedJniThreadState ts(env);
957 UNIMPLEMENTED(FATAL);
958 return 0;
959 }
960
961 static jdouble CallDoubleMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
962 ScopedJniThreadState ts(env);
963 UNIMPLEMENTED(FATAL);
964 return 0;
965 }
966
967 static jdouble CallDoubleMethodV(JNIEnv* env,
968 jobject obj, jmethodID methodID, va_list args) {
969 ScopedJniThreadState ts(env);
970 UNIMPLEMENTED(FATAL);
971 return 0;
972 }
973
974 static jdouble CallDoubleMethodA(JNIEnv* env,
975 jobject obj, jmethodID methodID, jvalue* args) {
976 ScopedJniThreadState ts(env);
977 UNIMPLEMENTED(FATAL);
978 return 0;
979 }
980
981 static void CallVoidMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
982 ScopedJniThreadState ts(env);
983 UNIMPLEMENTED(FATAL);
984 }
985
986 static void CallVoidMethodV(JNIEnv* env, jobject obj,
987 jmethodID methodID, va_list args) {
988 ScopedJniThreadState ts(env);
989 UNIMPLEMENTED(FATAL);
990 }
991
992 static void CallVoidMethodA(JNIEnv* env, jobject obj,
993 jmethodID methodID, jvalue* args) {
994 ScopedJniThreadState ts(env);
995 UNIMPLEMENTED(FATAL);
996 }
997
998 static jobject CallNonvirtualObjectMethod(JNIEnv* env,
999 jobject obj, jclass clazz, jmethodID methodID, ...) {
1000 ScopedJniThreadState ts(env);
1001 va_list ap;
1002 va_start(ap, methodID);
1003 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1004 jobject local_result = AddLocalReference<jobject>(ts, result.l);
1005 va_end(ap);
1006 return local_result;
1007 }
1008
1009 static jobject CallNonvirtualObjectMethodV(JNIEnv* env,
1010 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
1011 ScopedJniThreadState ts(env);
1012 JValue result = InvokeWithVarArgs(ts, obj, methodID, args);
1013 return AddLocalReference<jobject>(ts, result.l);
1014 }
1015
1016 static jobject CallNonvirtualObjectMethodA(JNIEnv* env,
1017 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
1018 ScopedJniThreadState ts(env);
1019 JValue result = InvokeWithJValues(ts, obj, methodID, args);
1020 return AddLocalReference<jobject>(ts, result.l);
1021 }
1022
1023 static jboolean CallNonvirtualBooleanMethod(JNIEnv* env,
1024 jobject obj, jclass clazz, jmethodID methodID, ...) {
1025 ScopedJniThreadState ts(env);
1026 va_list ap;
1027 va_start(ap, methodID);
1028 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1029 va_end(ap);
1030 return result.z;
1031 }
1032
1033 static jboolean CallNonvirtualBooleanMethodV(JNIEnv* env,
1034 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
1035 ScopedJniThreadState ts(env);
1036 return InvokeWithVarArgs(ts, obj, methodID, args).z;
1037 }
1038
1039 static jboolean CallNonvirtualBooleanMethodA(JNIEnv* env,
1040 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
1041 ScopedJniThreadState ts(env);
1042 return InvokeWithJValues(ts, obj, methodID, args).z;
1043 }
1044
1045 static jbyte CallNonvirtualByteMethod(JNIEnv* env,
1046 jobject obj, jclass clazz, jmethodID methodID, ...) {
1047 ScopedJniThreadState ts(env);
1048 va_list ap;
1049 va_start(ap, methodID);
1050 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1051 va_end(ap);
1052 return result.b;
1053 }
1054
1055 static jbyte CallNonvirtualByteMethodV(JNIEnv* env,
1056 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
1057 ScopedJniThreadState ts(env);
1058 return InvokeWithVarArgs(ts, obj, methodID, args).b;
1059 }
1060
1061 static jbyte CallNonvirtualByteMethodA(JNIEnv* env,
1062 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
1063 ScopedJniThreadState ts(env);
1064 return InvokeWithJValues(ts, obj, methodID, args).b;
1065 }
1066
1067 static jchar CallNonvirtualCharMethod(JNIEnv* env,
1068 jobject obj, jclass clazz, jmethodID methodID, ...) {
1069 ScopedJniThreadState ts(env);
1070 va_list ap;
1071 va_start(ap, methodID);
1072 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1073 va_end(ap);
1074 return result.c;
1075 }
1076
1077 static jchar CallNonvirtualCharMethodV(JNIEnv* env,
1078 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
1079 ScopedJniThreadState ts(env);
1080 return InvokeWithVarArgs(ts, obj, methodID, args).c;
1081 }
1082
1083 static jchar CallNonvirtualCharMethodA(JNIEnv* env,
1084 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
1085 ScopedJniThreadState ts(env);
1086 return InvokeWithJValues(ts, obj, methodID, args).c;
1087 }
1088
1089 static jshort CallNonvirtualShortMethod(JNIEnv* env,
1090 jobject obj, jclass clazz, jmethodID methodID, ...) {
1091 ScopedJniThreadState ts(env);
1092 va_list ap;
1093 va_start(ap, methodID);
1094 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1095 va_end(ap);
1096 return result.s;
1097 }
1098
1099 static jshort CallNonvirtualShortMethodV(JNIEnv* env,
1100 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
1101 ScopedJniThreadState ts(env);
1102 return InvokeWithVarArgs(ts, obj, methodID, args).s;
1103 }
1104
1105 static jshort CallNonvirtualShortMethodA(JNIEnv* env,
1106 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
1107 ScopedJniThreadState ts(env);
1108 return InvokeWithJValues(ts, obj, methodID, args).s;
1109 }
1110
1111 static jint CallNonvirtualIntMethod(JNIEnv* env,
1112 jobject obj, jclass clazz, jmethodID methodID, ...) {
1113 ScopedJniThreadState ts(env);
1114 va_list ap;
1115 va_start(ap, methodID);
1116 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1117 va_end(ap);
1118 return result.i;
1119 }
1120
1121 static jint CallNonvirtualIntMethodV(JNIEnv* env,
1122 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
1123 ScopedJniThreadState ts(env);
1124 return InvokeWithVarArgs(ts, obj, methodID, args).i;
1125 }
1126
1127 static jint CallNonvirtualIntMethodA(JNIEnv* env,
1128 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
1129 ScopedJniThreadState ts(env);
1130 return InvokeWithJValues(ts, obj, methodID, args).i;
1131 }
1132
1133 static jlong CallNonvirtualLongMethod(JNIEnv* env,
1134 jobject obj, jclass clazz, jmethodID methodID, ...) {
1135 ScopedJniThreadState ts(env);
1136 va_list ap;
1137 va_start(ap, methodID);
1138 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1139 va_end(ap);
1140 return result.j;
1141 }
1142
1143 static jlong CallNonvirtualLongMethodV(JNIEnv* env,
1144 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
1145 ScopedJniThreadState ts(env);
1146 return InvokeWithVarArgs(ts, obj, methodID, args).j;
1147 }
1148
1149 static jlong CallNonvirtualLongMethodA(JNIEnv* env,
1150 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
1151 ScopedJniThreadState ts(env);
1152 return InvokeWithJValues(ts, obj, methodID, args).j;
1153 }
1154
1155 static jfloat CallNonvirtualFloatMethod(JNIEnv* env,
1156 jobject obj, jclass clazz, jmethodID methodID, ...) {
1157 ScopedJniThreadState ts(env);
1158 va_list ap;
1159 va_start(ap, methodID);
1160 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1161 va_end(ap);
1162 return result.f;
1163 }
1164
1165 static jfloat CallNonvirtualFloatMethodV(JNIEnv* env,
1166 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
1167 ScopedJniThreadState ts(env);
1168 return InvokeWithVarArgs(ts, obj, methodID, args).f;
1169 }
1170
1171 static jfloat CallNonvirtualFloatMethodA(JNIEnv* env,
1172 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
1173 ScopedJniThreadState ts(env);
1174 return InvokeWithJValues(ts, obj, methodID, args).f;
1175 }
1176
1177 static jdouble CallNonvirtualDoubleMethod(JNIEnv* env,
1178 jobject obj, jclass clazz, jmethodID methodID, ...) {
1179 ScopedJniThreadState ts(env);
1180 va_list ap;
1181 va_start(ap, methodID);
1182 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1183 va_end(ap);
1184 return result.d;
1185 }
1186
1187 static jdouble CallNonvirtualDoubleMethodV(JNIEnv* env,
1188 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
1189 ScopedJniThreadState ts(env);
1190 return InvokeWithVarArgs(ts, obj, methodID, args).d;
1191 }
1192
1193 static jdouble CallNonvirtualDoubleMethodA(JNIEnv* env,
1194 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
1195 ScopedJniThreadState ts(env);
1196 return InvokeWithJValues(ts, obj, methodID, args).d;
1197 }
1198
1199 static void CallNonvirtualVoidMethod(JNIEnv* env,
1200 jobject obj, jclass clazz, jmethodID methodID, ...) {
1201 ScopedJniThreadState ts(env);
1202 va_list ap;
1203 va_start(ap, methodID);
1204 InvokeWithVarArgs(ts, obj, methodID, ap);
1205 va_end(ap);
1206 }
1207
1208 static void CallNonvirtualVoidMethodV(JNIEnv* env,
1209 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
1210 ScopedJniThreadState ts(env);
1211 InvokeWithVarArgs(ts, obj, methodID, args);
1212 }
1213
1214 static void CallNonvirtualVoidMethodA(JNIEnv* env,
1215 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
1216 ScopedJniThreadState ts(env);
1217 InvokeWithJValues(ts, obj, methodID, args);
1218 }
1219
1220 static jfieldID GetFieldID(JNIEnv* env,
1221 jclass c, const char* name, const char* sig) {
1222 ScopedJniThreadState ts(env);
1223 return FindFieldID(ts, c, name, sig, false);
1224 }
Carl Shapiroea4dca82011-08-01 13:45:38 -07001225
1226
Elliott Hughescdf53122011-08-19 15:46:09 -07001227 static jfieldID GetStaticFieldID(JNIEnv* env,
1228 jclass c, const char* name, const char* sig) {
1229 ScopedJniThreadState ts(env);
1230 return FindFieldID(ts, c, name, sig, true);
1231 }
Carl Shapiroea4dca82011-08-01 13:45:38 -07001232
Elliott Hughescdf53122011-08-19 15:46:09 -07001233 static jobject GetObjectField(JNIEnv* env, jobject obj, jfieldID fieldID) {
1234 ScopedJniThreadState ts(env);
1235 UNIMPLEMENTED(FATAL);
1236 return NULL;
1237 }
Carl Shapiroea4dca82011-08-01 13:45:38 -07001238
Elliott Hughescdf53122011-08-19 15:46:09 -07001239 static jboolean GetBooleanField(JNIEnv* env, jobject obj, jfieldID fieldID) {
1240 ScopedJniThreadState ts(env);
1241 UNIMPLEMENTED(FATAL);
1242 return JNI_FALSE;
1243 }
1244
1245 static jbyte GetByteField(JNIEnv* env, jobject obj, jfieldID fieldID) {
1246 ScopedJniThreadState ts(env);
1247 UNIMPLEMENTED(FATAL);
1248 return 0;
1249 }
1250
1251 static jchar GetCharField(JNIEnv* env, jobject obj, jfieldID fieldID) {
1252 ScopedJniThreadState ts(env);
1253 UNIMPLEMENTED(FATAL);
1254 return 0;
1255 }
1256
1257 static jshort GetShortField(JNIEnv* env, jobject obj, jfieldID fieldID) {
1258 ScopedJniThreadState ts(env);
1259 UNIMPLEMENTED(FATAL);
1260 return 0;
1261 }
1262
1263 static jint GetIntField(JNIEnv* env, jobject obj, jfieldID fieldID) {
1264 ScopedJniThreadState ts(env);
1265 UNIMPLEMENTED(FATAL);
1266 return 0;
1267 }
1268
1269 static jlong GetLongField(JNIEnv* env, jobject obj, jfieldID fieldID) {
1270 ScopedJniThreadState ts(env);
1271 UNIMPLEMENTED(FATAL);
1272 return 0;
1273 }
1274
1275 static jfloat GetFloatField(JNIEnv* env, jobject obj, jfieldID fieldID) {
1276 ScopedJniThreadState ts(env);
1277 UNIMPLEMENTED(FATAL);
1278 return 0;
1279 }
1280
1281 static jdouble GetDoubleField(JNIEnv* env, jobject obj, jfieldID fieldID) {
1282 ScopedJniThreadState ts(env);
1283 UNIMPLEMENTED(FATAL);
1284 return 0;
1285 }
1286
1287 static void SetObjectField(JNIEnv* env, jobject obj, jfieldID fieldID, jobject val) {
1288 ScopedJniThreadState ts(env);
1289 UNIMPLEMENTED(FATAL);
1290 }
1291
1292 static void SetBooleanField(JNIEnv* env, jobject obj, jfieldID fieldID, jboolean val) {
1293 ScopedJniThreadState ts(env);
1294 UNIMPLEMENTED(FATAL);
1295 }
1296
1297 static void SetByteField(JNIEnv* env, jobject obj, jfieldID fieldID, jbyte val) {
1298 ScopedJniThreadState ts(env);
1299 UNIMPLEMENTED(FATAL);
1300 }
1301
1302 static void SetCharField(JNIEnv* env, jobject obj, jfieldID fieldID, jchar val) {
1303 ScopedJniThreadState ts(env);
1304 UNIMPLEMENTED(FATAL);
1305 }
1306
1307 static void SetShortField(JNIEnv* env, jobject obj, jfieldID fieldID, jshort val) {
1308 ScopedJniThreadState ts(env);
1309 UNIMPLEMENTED(FATAL);
1310 }
1311
1312 static void SetIntField(JNIEnv* env, jobject obj, jfieldID fieldID, jint val) {
1313 ScopedJniThreadState ts(env);
1314 UNIMPLEMENTED(FATAL);
1315 }
1316
1317 static void SetLongField(JNIEnv* env, jobject obj, jfieldID fieldID, jlong val) {
1318 ScopedJniThreadState ts(env);
1319 UNIMPLEMENTED(FATAL);
1320 }
1321
1322 static void SetFloatField(JNIEnv* env, jobject obj, jfieldID fieldID, jfloat val) {
1323 ScopedJniThreadState ts(env);
1324 UNIMPLEMENTED(FATAL);
1325 }
1326
1327 static void SetDoubleField(JNIEnv* env, jobject obj, jfieldID fieldID, jdouble val) {
1328 ScopedJniThreadState ts(env);
1329 UNIMPLEMENTED(FATAL);
1330 }
1331
1332 static jobject CallStaticObjectMethod(JNIEnv* env,
1333 jclass clazz, jmethodID methodID, ...) {
1334 ScopedJniThreadState ts(env);
1335 va_list ap;
1336 va_start(ap, methodID);
1337 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1338 jobject local_result = AddLocalReference<jobject>(ts, result.l);
1339 va_end(ap);
1340 return local_result;
1341 }
1342
1343 static jobject CallStaticObjectMethodV(JNIEnv* env,
1344 jclass clazz, jmethodID methodID, va_list args) {
1345 ScopedJniThreadState ts(env);
1346 JValue result = InvokeWithVarArgs(ts, NULL, methodID, args);
1347 return AddLocalReference<jobject>(ts, result.l);
1348 }
1349
1350 static jobject CallStaticObjectMethodA(JNIEnv* env,
1351 jclass clazz, jmethodID methodID, jvalue* args) {
1352 ScopedJniThreadState ts(env);
1353 JValue result = InvokeWithJValues(ts, NULL, methodID, args);
1354 return AddLocalReference<jobject>(ts, result.l);
1355 }
1356
1357 static jboolean CallStaticBooleanMethod(JNIEnv* env,
1358 jclass clazz, jmethodID methodID, ...) {
1359 ScopedJniThreadState ts(env);
1360 va_list ap;
1361 va_start(ap, methodID);
1362 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1363 va_end(ap);
1364 return result.z;
1365 }
1366
1367 static jboolean CallStaticBooleanMethodV(JNIEnv* env,
1368 jclass clazz, jmethodID methodID, va_list args) {
1369 ScopedJniThreadState ts(env);
1370 return InvokeWithVarArgs(ts, NULL, methodID, args).z;
1371 }
1372
1373 static jboolean CallStaticBooleanMethodA(JNIEnv* env,
1374 jclass clazz, jmethodID methodID, jvalue* args) {
1375 ScopedJniThreadState ts(env);
1376 return InvokeWithJValues(ts, NULL, methodID, args).z;
1377 }
1378
1379 static jbyte CallStaticByteMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
1380 ScopedJniThreadState ts(env);
1381 va_list ap;
1382 va_start(ap, methodID);
1383 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1384 va_end(ap);
1385 return result.b;
1386 }
1387
1388 static jbyte CallStaticByteMethodV(JNIEnv* env,
1389 jclass clazz, jmethodID methodID, va_list args) {
1390 ScopedJniThreadState ts(env);
1391 return InvokeWithVarArgs(ts, NULL, methodID, args).b;
1392 }
1393
1394 static jbyte CallStaticByteMethodA(JNIEnv* env,
1395 jclass clazz, jmethodID methodID, jvalue* args) {
1396 ScopedJniThreadState ts(env);
1397 return InvokeWithJValues(ts, NULL, methodID, args).b;
1398 }
1399
1400 static jchar CallStaticCharMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
1401 ScopedJniThreadState ts(env);
1402 va_list ap;
1403 va_start(ap, methodID);
1404 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1405 va_end(ap);
1406 return result.c;
1407 }
1408
1409 static jchar CallStaticCharMethodV(JNIEnv* env,
1410 jclass clazz, jmethodID methodID, va_list args) {
1411 ScopedJniThreadState ts(env);
1412 return InvokeWithVarArgs(ts, NULL, methodID, args).c;
1413 }
1414
1415 static jchar CallStaticCharMethodA(JNIEnv* env,
1416 jclass clazz, jmethodID methodID, jvalue* args) {
1417 ScopedJniThreadState ts(env);
1418 return InvokeWithJValues(ts, NULL, methodID, args).c;
1419 }
1420
1421 static jshort CallStaticShortMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
1422 ScopedJniThreadState ts(env);
1423 va_list ap;
1424 va_start(ap, methodID);
1425 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1426 va_end(ap);
1427 return result.s;
1428 }
1429
1430 static jshort CallStaticShortMethodV(JNIEnv* env,
1431 jclass clazz, jmethodID methodID, va_list args) {
1432 ScopedJniThreadState ts(env);
1433 return InvokeWithVarArgs(ts, NULL, methodID, args).s;
1434 }
1435
1436 static jshort CallStaticShortMethodA(JNIEnv* env,
1437 jclass clazz, jmethodID methodID, jvalue* args) {
1438 ScopedJniThreadState ts(env);
1439 return InvokeWithJValues(ts, NULL, methodID, args).s;
1440 }
1441
1442 static jint CallStaticIntMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
1443 ScopedJniThreadState ts(env);
1444 va_list ap;
1445 va_start(ap, methodID);
1446 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1447 va_end(ap);
1448 return result.i;
1449 }
1450
1451 static jint CallStaticIntMethodV(JNIEnv* env,
1452 jclass clazz, jmethodID methodID, va_list args) {
1453 ScopedJniThreadState ts(env);
1454 return InvokeWithVarArgs(ts, NULL, methodID, args).i;
1455 }
1456
1457 static jint CallStaticIntMethodA(JNIEnv* env,
1458 jclass clazz, jmethodID methodID, jvalue* args) {
1459 ScopedJniThreadState ts(env);
1460 return InvokeWithJValues(ts, NULL, methodID, args).i;
1461 }
1462
1463 static jlong CallStaticLongMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
1464 ScopedJniThreadState ts(env);
1465 va_list ap;
1466 va_start(ap, methodID);
1467 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1468 va_end(ap);
1469 return result.j;
1470 }
1471
1472 static jlong CallStaticLongMethodV(JNIEnv* env,
1473 jclass clazz, jmethodID methodID, va_list args) {
1474 ScopedJniThreadState ts(env);
1475 return InvokeWithVarArgs(ts, NULL, methodID, args).j;
1476 }
1477
1478 static jlong CallStaticLongMethodA(JNIEnv* env,
1479 jclass clazz, jmethodID methodID, jvalue* args) {
1480 ScopedJniThreadState ts(env);
1481 return InvokeWithJValues(ts, NULL, methodID, args).j;
1482 }
1483
1484 static jfloat CallStaticFloatMethod(JNIEnv* env, jclass cls, jmethodID methodID, ...) {
1485 ScopedJniThreadState ts(env);
1486 va_list ap;
1487 va_start(ap, methodID);
1488 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1489 va_end(ap);
1490 return result.f;
1491 }
1492
1493 static jfloat CallStaticFloatMethodV(JNIEnv* env,
1494 jclass clazz, jmethodID methodID, va_list args) {
1495 ScopedJniThreadState ts(env);
1496 return InvokeWithVarArgs(ts, NULL, methodID, args).f;
1497 }
1498
1499 static jfloat CallStaticFloatMethodA(JNIEnv* env,
1500 jclass clazz, jmethodID methodID, jvalue* args) {
1501 ScopedJniThreadState ts(env);
1502 return InvokeWithJValues(ts, NULL, methodID, args).f;
1503 }
1504
1505 static jdouble CallStaticDoubleMethod(JNIEnv* env, jclass cls, jmethodID methodID, ...) {
1506 ScopedJniThreadState ts(env);
1507 va_list ap;
1508 va_start(ap, methodID);
1509 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1510 va_end(ap);
1511 return result.d;
1512 }
1513
1514 static jdouble CallStaticDoubleMethodV(JNIEnv* env,
1515 jclass clazz, jmethodID methodID, va_list args) {
1516 ScopedJniThreadState ts(env);
1517 return InvokeWithVarArgs(ts, NULL, methodID, args).d;
1518 }
1519
1520 static jdouble CallStaticDoubleMethodA(JNIEnv* env,
1521 jclass clazz, jmethodID methodID, jvalue* args) {
1522 ScopedJniThreadState ts(env);
1523 return InvokeWithJValues(ts, NULL, methodID, args).d;
1524 }
1525
1526 static void CallStaticVoidMethod(JNIEnv* env, jclass cls, jmethodID methodID, ...) {
1527 ScopedJniThreadState ts(env);
1528 va_list ap;
1529 va_start(ap, methodID);
1530 InvokeWithVarArgs(ts, NULL, methodID, ap);
1531 va_end(ap);
1532 }
1533
1534 static void CallStaticVoidMethodV(JNIEnv* env,
1535 jclass cls, jmethodID methodID, va_list args) {
1536 ScopedJniThreadState ts(env);
1537 InvokeWithVarArgs(ts, NULL, methodID, args);
1538 }
1539
1540 static void CallStaticVoidMethodA(JNIEnv* env,
1541 jclass cls, jmethodID methodID, jvalue* args) {
1542 ScopedJniThreadState ts(env);
1543 InvokeWithJValues(ts, NULL, methodID, args);
1544 }
1545
1546 static jobject GetStaticObjectField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
1547 ScopedJniThreadState ts(env);
1548 UNIMPLEMENTED(FATAL);
1549 return NULL;
1550 }
1551
1552 static jboolean GetStaticBooleanField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
1553 ScopedJniThreadState ts(env);
1554 UNIMPLEMENTED(FATAL);
1555 return JNI_FALSE;
1556 }
1557
1558 static jbyte GetStaticByteField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
1559 ScopedJniThreadState ts(env);
1560 UNIMPLEMENTED(FATAL);
1561 return 0;
1562 }
1563
1564 static jchar GetStaticCharField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
1565 ScopedJniThreadState ts(env);
1566 UNIMPLEMENTED(FATAL);
1567 return 0;
1568 }
1569
1570 static jshort GetStaticShortField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
1571 ScopedJniThreadState ts(env);
1572 UNIMPLEMENTED(FATAL);
1573 return 0;
1574 }
1575
1576 static jint GetStaticIntField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
1577 ScopedJniThreadState ts(env);
1578 UNIMPLEMENTED(FATAL);
1579 return 0;
1580 }
1581
1582 static jlong GetStaticLongField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
1583 ScopedJniThreadState ts(env);
1584 UNIMPLEMENTED(FATAL);
1585 return 0;
1586 }
1587
1588 static jfloat GetStaticFloatField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
1589 ScopedJniThreadState ts(env);
1590 UNIMPLEMENTED(FATAL);
1591 return 0;
1592 }
1593
1594 static jdouble GetStaticDoubleField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
1595 ScopedJniThreadState ts(env);
1596 UNIMPLEMENTED(FATAL);
1597 return 0;
1598 }
1599
1600 static void SetStaticObjectField(JNIEnv* env,
1601 jclass clazz, jfieldID fieldID, jobject value) {
1602 ScopedJniThreadState ts(env);
1603 UNIMPLEMENTED(FATAL);
1604 }
1605
1606 static void SetStaticBooleanField(JNIEnv* env,
1607 jclass clazz, jfieldID fieldID, jboolean value) {
1608 ScopedJniThreadState ts(env);
1609 UNIMPLEMENTED(FATAL);
1610 }
1611
1612 static void SetStaticByteField(JNIEnv* env,
1613 jclass clazz, jfieldID fieldID, jbyte value) {
1614 ScopedJniThreadState ts(env);
1615 UNIMPLEMENTED(FATAL);
1616 }
1617
1618 static void SetStaticCharField(JNIEnv* env,
1619 jclass clazz, jfieldID fieldID, jchar value) {
1620 ScopedJniThreadState ts(env);
1621 UNIMPLEMENTED(FATAL);
1622 }
1623
1624 static void SetStaticShortField(JNIEnv* env,
1625 jclass clazz, jfieldID fieldID, jshort value) {
1626 ScopedJniThreadState ts(env);
1627 UNIMPLEMENTED(FATAL);
1628 }
1629
1630 static void SetStaticIntField(JNIEnv* env,
1631 jclass clazz, jfieldID fieldID, jint value) {
1632 ScopedJniThreadState ts(env);
1633 UNIMPLEMENTED(FATAL);
1634 }
1635
1636 static void SetStaticLongField(JNIEnv* env,
1637 jclass clazz, jfieldID fieldID, jlong value) {
1638 ScopedJniThreadState ts(env);
1639 UNIMPLEMENTED(FATAL);
1640 }
1641
1642 static void SetStaticFloatField(JNIEnv* env,
1643 jclass clazz, jfieldID fieldID, jfloat value) {
1644 ScopedJniThreadState ts(env);
1645 UNIMPLEMENTED(FATAL);
1646 }
1647
1648 static void SetStaticDoubleField(JNIEnv* env,
1649 jclass clazz, jfieldID fieldID, jdouble value) {
1650 ScopedJniThreadState ts(env);
1651 UNIMPLEMENTED(FATAL);
1652 }
1653
1654 static jstring NewString(JNIEnv* env, const jchar* unicode, jsize len) {
1655 ScopedJniThreadState ts(env);
1656 UNIMPLEMENTED(FATAL);
1657 return NULL;
1658 }
1659
1660 static jsize GetStringLength(JNIEnv* env, jstring str) {
1661 ScopedJniThreadState ts(env);
1662 UNIMPLEMENTED(FATAL);
1663 return 0;
1664 }
1665
1666 static const jchar* GetStringChars(JNIEnv* env, jstring str, jboolean* isCopy) {
1667 ScopedJniThreadState ts(env);
1668 UNIMPLEMENTED(FATAL);
1669 return NULL;
1670 }
1671
1672 static void ReleaseStringChars(JNIEnv* env, jstring str, const jchar* chars) {
1673 ScopedJniThreadState ts(env);
1674 UNIMPLEMENTED(FATAL);
1675 }
1676
1677 static jstring NewStringUTF(JNIEnv* env, const char* utf) {
1678 ScopedJniThreadState ts(env);
1679 if (utf == NULL) {
1680 return NULL;
1681 }
1682 String* result = String::AllocFromModifiedUtf8(utf);
1683 return AddLocalReference<jstring>(ts, result);
1684 }
1685
1686 static jsize GetStringUTFLength(JNIEnv* env, jstring str) {
1687 ScopedJniThreadState ts(env);
1688 UNIMPLEMENTED(FATAL);
1689 return 0;
1690 }
1691
1692 static const char* GetStringUTFChars(JNIEnv* env, jstring str, jboolean* isCopy) {
1693 ScopedJniThreadState ts(env);
1694 UNIMPLEMENTED(FATAL);
1695 return NULL;
1696 }
1697
1698 static void ReleaseStringUTFChars(JNIEnv* env, jstring str, const char* chars) {
1699 ScopedJniThreadState ts(env);
1700 UNIMPLEMENTED(FATAL);
1701 }
1702
1703 static jsize GetArrayLength(JNIEnv* env, jarray array) {
1704 ScopedJniThreadState ts(env);
1705 UNIMPLEMENTED(FATAL);
1706 return 0;
1707 }
1708
1709 static jobject GetObjectArrayElement(JNIEnv* env, jobjectArray array, jsize index) {
1710 ScopedJniThreadState ts(env);
1711 UNIMPLEMENTED(FATAL);
1712 return NULL;
1713 }
1714
1715 static void SetObjectArrayElement(JNIEnv* env,
1716 jobjectArray java_array, jsize index, jobject java_value) {
1717 ScopedJniThreadState ts(env);
1718 ObjectArray<Object>* array = Decode<ObjectArray<Object>*>(ts, java_array);
1719 Object* value = Decode<Object*>(ts, java_value);
1720 array->Set(index, value);
1721 }
1722
1723 static jbooleanArray NewBooleanArray(JNIEnv* env, jsize length) {
1724 ScopedJniThreadState ts(env);
1725 return NewPrimitiveArray<jbooleanArray, BooleanArray>(ts, length);
1726 }
1727
1728 static jbyteArray NewByteArray(JNIEnv* env, jsize length) {
1729 ScopedJniThreadState ts(env);
1730 return NewPrimitiveArray<jbyteArray, ByteArray>(ts, length);
1731 }
1732
1733 static jcharArray NewCharArray(JNIEnv* env, jsize length) {
1734 ScopedJniThreadState ts(env);
1735 return NewPrimitiveArray<jcharArray, CharArray>(ts, length);
1736 }
1737
1738 static jdoubleArray NewDoubleArray(JNIEnv* env, jsize length) {
1739 ScopedJniThreadState ts(env);
1740 return NewPrimitiveArray<jdoubleArray, DoubleArray>(ts, length);
1741 }
1742
1743 static jfloatArray NewFloatArray(JNIEnv* env, jsize length) {
1744 ScopedJniThreadState ts(env);
1745 return NewPrimitiveArray<jfloatArray, FloatArray>(ts, length);
1746 }
1747
1748 static jintArray NewIntArray(JNIEnv* env, jsize length) {
1749 ScopedJniThreadState ts(env);
1750 return NewPrimitiveArray<jintArray, IntArray>(ts, length);
1751 }
1752
1753 static jlongArray NewLongArray(JNIEnv* env, jsize length) {
1754 ScopedJniThreadState ts(env);
1755 return NewPrimitiveArray<jlongArray, LongArray>(ts, length);
1756 }
1757
1758 static jobjectArray NewObjectArray(JNIEnv* env, jsize length, jclass element_jclass, jobject initial_element) {
1759 ScopedJniThreadState ts(env);
1760 CHECK_GE(length, 0); // TODO: ReportJniError
1761
1762 // Compute the array class corresponding to the given element class.
1763 Class* element_class = Decode<Class*>(ts, element_jclass);
1764 std::string descriptor;
1765 descriptor += "[";
1766 descriptor += element_class->GetDescriptor().ToString();
1767
1768 // Find the class.
1769 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
1770 // TODO: need to get the appropriate ClassLoader.
1771 Class* array_class = class_linker->FindClass(descriptor, NULL);
1772 if (array_class == NULL) {
1773 return NULL;
1774 }
1775
1776 ObjectArray<Object>* result = ObjectArray<Object>::Alloc(array_class, length);
1777 CHECK(initial_element == NULL); // TODO: support initial_element
1778 return AddLocalReference<jobjectArray>(ts, result);
1779 }
1780
1781 static jshortArray NewShortArray(JNIEnv* env, jsize length) {
1782 ScopedJniThreadState ts(env);
1783 return NewPrimitiveArray<jshortArray, ShortArray>(ts, length);
1784 }
1785
1786 static jboolean* GetBooleanArrayElements(JNIEnv* env,
1787 jbooleanArray array, jboolean* isCopy) {
1788 ScopedJniThreadState ts(env);
1789 UNIMPLEMENTED(FATAL);
1790 return NULL;
1791 }
1792
1793 static jbyte* GetByteArrayElements(JNIEnv* env, jbyteArray array, jboolean* isCopy) {
1794 ScopedJniThreadState ts(env);
1795 UNIMPLEMENTED(FATAL);
1796 return NULL;
1797 }
1798
1799 static jchar* GetCharArrayElements(JNIEnv* env, jcharArray array, jboolean* isCopy) {
1800 ScopedJniThreadState ts(env);
1801 UNIMPLEMENTED(FATAL);
1802 return NULL;
1803 }
1804
1805 static jshort* GetShortArrayElements(JNIEnv* env,
1806 jshortArray array, jboolean* isCopy) {
1807 ScopedJniThreadState ts(env);
1808 UNIMPLEMENTED(FATAL);
1809 return NULL;
1810 }
1811
1812 static jint* GetIntArrayElements(JNIEnv* env, jintArray array, jboolean* isCopy) {
1813 ScopedJniThreadState ts(env);
1814 UNIMPLEMENTED(FATAL);
1815 return NULL;
1816 }
1817
1818 static jlong* GetLongArrayElements(JNIEnv* env, jlongArray array, jboolean* isCopy) {
1819 ScopedJniThreadState ts(env);
1820 UNIMPLEMENTED(FATAL);
1821 return NULL;
1822 }
1823
1824 static jfloat* GetFloatArrayElements(JNIEnv* env,
1825 jfloatArray array, jboolean* isCopy) {
1826 ScopedJniThreadState ts(env);
1827 UNIMPLEMENTED(FATAL);
1828 return NULL;
1829 }
1830
1831 static jdouble* GetDoubleArrayElements(JNIEnv* env,
1832 jdoubleArray array, jboolean* isCopy) {
1833 ScopedJniThreadState ts(env);
1834 UNIMPLEMENTED(FATAL);
1835 return NULL;
1836 }
1837
1838 static void ReleaseBooleanArrayElements(JNIEnv* env,
1839 jbooleanArray array, jboolean* elems, jint mode) {
1840 ScopedJniThreadState ts(env);
1841 UNIMPLEMENTED(FATAL);
1842 }
1843
1844 static void ReleaseByteArrayElements(JNIEnv* env,
1845 jbyteArray array, jbyte* elems, jint mode) {
1846 ScopedJniThreadState ts(env);
1847 UNIMPLEMENTED(FATAL);
1848 }
1849
1850 static void ReleaseCharArrayElements(JNIEnv* env,
1851 jcharArray array, jchar* elems, jint mode) {
1852 ScopedJniThreadState ts(env);
1853 UNIMPLEMENTED(FATAL);
1854 }
1855
1856 static void ReleaseShortArrayElements(JNIEnv* env,
1857 jshortArray array, jshort* elems, jint mode) {
1858 ScopedJniThreadState ts(env);
1859 UNIMPLEMENTED(FATAL);
1860 }
1861
1862 static void ReleaseIntArrayElements(JNIEnv* env,
1863 jintArray array, jint* elems, jint mode) {
1864 ScopedJniThreadState ts(env);
1865 UNIMPLEMENTED(FATAL);
1866 }
1867
1868 static void ReleaseLongArrayElements(JNIEnv* env,
1869 jlongArray array, jlong* elems, jint mode) {
1870 ScopedJniThreadState ts(env);
1871 UNIMPLEMENTED(FATAL);
1872 }
1873
1874 static void ReleaseFloatArrayElements(JNIEnv* env,
1875 jfloatArray array, jfloat* elems, jint mode) {
1876 ScopedJniThreadState ts(env);
1877 UNIMPLEMENTED(FATAL);
1878 }
1879
1880 static void ReleaseDoubleArrayElements(JNIEnv* env,
1881 jdoubleArray array, jdouble* elems, jint mode) {
1882 ScopedJniThreadState ts(env);
1883 UNIMPLEMENTED(FATAL);
1884 }
1885
1886 static void GetBooleanArrayRegion(JNIEnv* env,
1887 jbooleanArray array, jsize start, jsize l, jboolean* buf) {
1888 ScopedJniThreadState ts(env);
1889 UNIMPLEMENTED(FATAL);
1890 }
1891
1892 static void GetByteArrayRegion(JNIEnv* env,
1893 jbyteArray array, jsize start, jsize len, jbyte* buf) {
1894 ScopedJniThreadState ts(env);
1895 UNIMPLEMENTED(FATAL);
1896 }
1897
1898 static void GetCharArrayRegion(JNIEnv* env,
1899 jcharArray array, jsize start, jsize len, jchar* buf) {
1900 ScopedJniThreadState ts(env);
1901 UNIMPLEMENTED(FATAL);
1902 }
1903
1904 static void GetShortArrayRegion(JNIEnv* env,
1905 jshortArray array, jsize start, jsize len, jshort* buf) {
1906 ScopedJniThreadState ts(env);
1907 UNIMPLEMENTED(FATAL);
1908 }
1909
1910 static void GetIntArrayRegion(JNIEnv* env,
1911 jintArray array, jsize start, jsize len, jint* buf) {
1912 ScopedJniThreadState ts(env);
1913 UNIMPLEMENTED(FATAL);
1914 }
1915
1916 static void GetLongArrayRegion(JNIEnv* env,
1917 jlongArray array, jsize start, jsize len, jlong* buf) {
1918 ScopedJniThreadState ts(env);
1919 UNIMPLEMENTED(FATAL);
1920 }
1921
1922 static void GetFloatArrayRegion(JNIEnv* env,
1923 jfloatArray array, jsize start, jsize len, jfloat* buf) {
1924 ScopedJniThreadState ts(env);
1925 UNIMPLEMENTED(FATAL);
1926 }
1927
1928 static void GetDoubleArrayRegion(JNIEnv* env,
1929 jdoubleArray array, jsize start, jsize len, jdouble* buf) {
1930 ScopedJniThreadState ts(env);
1931 UNIMPLEMENTED(FATAL);
1932 }
1933
1934 static void SetBooleanArrayRegion(JNIEnv* env,
1935 jbooleanArray array, jsize start, jsize l, const jboolean* buf) {
1936 ScopedJniThreadState ts(env);
1937 UNIMPLEMENTED(FATAL);
1938 }
1939
1940 static void SetByteArrayRegion(JNIEnv* env,
1941 jbyteArray array, jsize start, jsize len, const jbyte* buf) {
1942 ScopedJniThreadState ts(env);
1943 UNIMPLEMENTED(FATAL);
1944 }
1945
1946 static void SetCharArrayRegion(JNIEnv* env,
1947 jcharArray array, jsize start, jsize len, const jchar* buf) {
1948 ScopedJniThreadState ts(env);
1949 UNIMPLEMENTED(FATAL);
1950 }
1951
1952 static void SetShortArrayRegion(JNIEnv* env,
1953 jshortArray array, jsize start, jsize len, const jshort* buf) {
1954 ScopedJniThreadState ts(env);
1955 UNIMPLEMENTED(FATAL);
1956 }
1957
1958 static void SetIntArrayRegion(JNIEnv* env,
1959 jintArray array, jsize start, jsize len, const jint* buf) {
1960 ScopedJniThreadState ts(env);
1961 UNIMPLEMENTED(FATAL);
1962 }
1963
1964 static void SetLongArrayRegion(JNIEnv* env,
1965 jlongArray array, jsize start, jsize len, const jlong* buf) {
1966 ScopedJniThreadState ts(env);
1967 UNIMPLEMENTED(FATAL);
1968 }
1969
1970 static void SetFloatArrayRegion(JNIEnv* env,
1971 jfloatArray array, jsize start, jsize len, const jfloat* buf) {
1972 ScopedJniThreadState ts(env);
1973 UNIMPLEMENTED(FATAL);
1974 }
1975
1976 static void SetDoubleArrayRegion(JNIEnv* env,
1977 jdoubleArray array, jsize start, jsize len, const jdouble* buf) {
1978 ScopedJniThreadState ts(env);
1979 UNIMPLEMENTED(FATAL);
1980 }
1981
1982 static jint RegisterNatives(JNIEnv* env,
1983 jclass clazz, const JNINativeMethod* methods, jint nMethods) {
1984 ScopedJniThreadState ts(env);
1985 Class* klass = Decode<Class*>(ts, clazz);
1986 for(int i = 0; i < nMethods; i++) {
1987 const char* name = methods[i].name;
1988 const char* sig = methods[i].signature;
1989
1990 if (*sig == '!') {
1991 // TODO: fast jni. it's too noisy to log all these.
1992 ++sig;
1993 }
1994
1995 Method* method = klass->FindDirectMethod(name, sig);
1996 if (method == NULL) {
1997 method = klass->FindVirtualMethod(name, sig);
1998 }
1999 if (method == NULL) {
2000 Thread* self = Thread::Current();
2001 std::string class_name = klass->GetDescriptor().ToString();
2002 // TODO: pretty print method names through a single routine
2003 self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
2004 "no method \"%s.%s%s\"",
2005 class_name.c_str(), name, sig);
2006 return JNI_ERR;
2007 } else if (!method->IsNative()) {
2008 Thread* self = Thread::Current();
2009 std::string class_name = klass->GetDescriptor().ToString();
2010 // TODO: pretty print method names through a single routine
2011 self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
2012 "method \"%s.%s%s\" is not native",
2013 class_name.c_str(), name, sig);
2014 return JNI_ERR;
2015 }
2016 method->RegisterNative(methods[i].fnPtr);
2017 }
2018 return JNI_OK;
2019 }
2020
2021 static jint UnregisterNatives(JNIEnv* env, jclass clazz) {
2022 ScopedJniThreadState ts(env);
2023 UNIMPLEMENTED(FATAL);
2024 return 0;
2025 }
2026
2027 static jint MonitorEnter(JNIEnv* env, jobject obj) {
2028 ScopedJniThreadState ts(env);
2029 UNIMPLEMENTED(WARNING);
2030 return 0;
2031 }
2032
2033 static jint MonitorExit(JNIEnv* env, jobject obj) {
2034 ScopedJniThreadState ts(env);
2035 UNIMPLEMENTED(WARNING);
2036 return 0;
2037 }
2038
2039 static jint GetJavaVM(JNIEnv* env, JavaVM** vm) {
2040 ScopedJniThreadState ts(env);
2041 Runtime* runtime = Runtime::Current();
2042 if (runtime != NULL) {
2043 *vm = reinterpret_cast<JavaVM*>(runtime->GetJavaVM());
2044 } else {
2045 *vm = NULL;
2046 }
2047 return (*vm != NULL) ? JNI_OK : JNI_ERR;
2048 }
2049
2050 static void GetStringRegion(JNIEnv* env,
2051 jstring str, jsize start, jsize len, jchar* buf) {
2052 ScopedJniThreadState ts(env);
2053 UNIMPLEMENTED(FATAL);
2054 }
2055
2056 static void GetStringUTFRegion(JNIEnv* env,
2057 jstring str, jsize start, jsize len, char* buf) {
2058 ScopedJniThreadState ts(env);
2059 UNIMPLEMENTED(FATAL);
2060 }
2061
2062 static void* GetPrimitiveArrayCritical(JNIEnv* env,
2063 jarray array, jboolean* isCopy) {
2064 ScopedJniThreadState ts(env);
2065 UNIMPLEMENTED(FATAL);
2066 return NULL;
2067 }
2068
2069 static void ReleasePrimitiveArrayCritical(JNIEnv* env,
2070 jarray array, void* carray, jint mode) {
2071 ScopedJniThreadState ts(env);
2072 UNIMPLEMENTED(FATAL);
2073 }
2074
2075 static const jchar* GetStringCritical(JNIEnv* env, jstring s, jboolean* isCopy) {
2076 ScopedJniThreadState ts(env);
2077 UNIMPLEMENTED(FATAL);
2078 return NULL;
2079 }
2080
2081 static void ReleaseStringCritical(JNIEnv* env, jstring s, const jchar* cstr) {
2082 ScopedJniThreadState ts(env);
2083 UNIMPLEMENTED(FATAL);
2084 }
2085
2086 static jboolean ExceptionCheck(JNIEnv* env) {
2087 ScopedJniThreadState ts(env);
2088 return ts.Self()->IsExceptionPending() ? JNI_TRUE : JNI_FALSE;
2089 }
2090
2091 static jobject NewDirectByteBuffer(JNIEnv* env, void* address, jlong capacity) {
2092 ScopedJniThreadState ts(env);
2093 UNIMPLEMENTED(FATAL);
2094 return NULL;
2095 }
2096
2097 static void* GetDirectBufferAddress(JNIEnv* env, jobject buf) {
2098 ScopedJniThreadState ts(env);
2099 UNIMPLEMENTED(FATAL);
2100 return NULL;
2101 }
2102
2103 static jlong GetDirectBufferCapacity(JNIEnv* env, jobject buf) {
2104 ScopedJniThreadState ts(env);
2105 UNIMPLEMENTED(FATAL);
2106 return 0;
2107 }
2108
2109 static jobjectRefType GetObjectRefType(JNIEnv* env, jobject jobj) {
2110 ScopedJniThreadState ts(env);
2111 UNIMPLEMENTED(FATAL);
2112 return JNIInvalidRefType;
2113 }
2114};
Carl Shapiroea4dca82011-08-01 13:45:38 -07002115
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002116static const struct JNINativeInterface gNativeInterface = {
Carl Shapiroea4dca82011-08-01 13:45:38 -07002117 NULL, // reserved0.
2118 NULL, // reserved1.
2119 NULL, // reserved2.
2120 NULL, // reserved3.
Elliott Hughescdf53122011-08-19 15:46:09 -07002121 JNI::GetVersion,
2122 JNI::DefineClass,
2123 JNI::FindClass,
2124 JNI::FromReflectedMethod,
2125 JNI::FromReflectedField,
2126 JNI::ToReflectedMethod,
2127 JNI::GetSuperclass,
2128 JNI::IsAssignableFrom,
2129 JNI::ToReflectedField,
2130 JNI::Throw,
2131 JNI::ThrowNew,
2132 JNI::ExceptionOccurred,
2133 JNI::ExceptionDescribe,
2134 JNI::ExceptionClear,
2135 JNI::FatalError,
2136 JNI::PushLocalFrame,
2137 JNI::PopLocalFrame,
2138 JNI::NewGlobalRef,
2139 JNI::DeleteGlobalRef,
2140 JNI::DeleteLocalRef,
2141 JNI::IsSameObject,
2142 JNI::NewLocalRef,
2143 JNI::EnsureLocalCapacity,
2144 JNI::AllocObject,
2145 JNI::NewObject,
2146 JNI::NewObjectV,
2147 JNI::NewObjectA,
2148 JNI::GetObjectClass,
2149 JNI::IsInstanceOf,
2150 JNI::GetMethodID,
2151 JNI::CallObjectMethod,
2152 JNI::CallObjectMethodV,
2153 JNI::CallObjectMethodA,
2154 JNI::CallBooleanMethod,
2155 JNI::CallBooleanMethodV,
2156 JNI::CallBooleanMethodA,
2157 JNI::CallByteMethod,
2158 JNI::CallByteMethodV,
2159 JNI::CallByteMethodA,
2160 JNI::CallCharMethod,
2161 JNI::CallCharMethodV,
2162 JNI::CallCharMethodA,
2163 JNI::CallShortMethod,
2164 JNI::CallShortMethodV,
2165 JNI::CallShortMethodA,
2166 JNI::CallIntMethod,
2167 JNI::CallIntMethodV,
2168 JNI::CallIntMethodA,
2169 JNI::CallLongMethod,
2170 JNI::CallLongMethodV,
2171 JNI::CallLongMethodA,
2172 JNI::CallFloatMethod,
2173 JNI::CallFloatMethodV,
2174 JNI::CallFloatMethodA,
2175 JNI::CallDoubleMethod,
2176 JNI::CallDoubleMethodV,
2177 JNI::CallDoubleMethodA,
2178 JNI::CallVoidMethod,
2179 JNI::CallVoidMethodV,
2180 JNI::CallVoidMethodA,
2181 JNI::CallNonvirtualObjectMethod,
2182 JNI::CallNonvirtualObjectMethodV,
2183 JNI::CallNonvirtualObjectMethodA,
2184 JNI::CallNonvirtualBooleanMethod,
2185 JNI::CallNonvirtualBooleanMethodV,
2186 JNI::CallNonvirtualBooleanMethodA,
2187 JNI::CallNonvirtualByteMethod,
2188 JNI::CallNonvirtualByteMethodV,
2189 JNI::CallNonvirtualByteMethodA,
2190 JNI::CallNonvirtualCharMethod,
2191 JNI::CallNonvirtualCharMethodV,
2192 JNI::CallNonvirtualCharMethodA,
2193 JNI::CallNonvirtualShortMethod,
2194 JNI::CallNonvirtualShortMethodV,
2195 JNI::CallNonvirtualShortMethodA,
2196 JNI::CallNonvirtualIntMethod,
2197 JNI::CallNonvirtualIntMethodV,
2198 JNI::CallNonvirtualIntMethodA,
2199 JNI::CallNonvirtualLongMethod,
2200 JNI::CallNonvirtualLongMethodV,
2201 JNI::CallNonvirtualLongMethodA,
2202 JNI::CallNonvirtualFloatMethod,
2203 JNI::CallNonvirtualFloatMethodV,
2204 JNI::CallNonvirtualFloatMethodA,
2205 JNI::CallNonvirtualDoubleMethod,
2206 JNI::CallNonvirtualDoubleMethodV,
2207 JNI::CallNonvirtualDoubleMethodA,
2208 JNI::CallNonvirtualVoidMethod,
2209 JNI::CallNonvirtualVoidMethodV,
2210 JNI::CallNonvirtualVoidMethodA,
2211 JNI::GetFieldID,
2212 JNI::GetObjectField,
2213 JNI::GetBooleanField,
2214 JNI::GetByteField,
2215 JNI::GetCharField,
2216 JNI::GetShortField,
2217 JNI::GetIntField,
2218 JNI::GetLongField,
2219 JNI::GetFloatField,
2220 JNI::GetDoubleField,
2221 JNI::SetObjectField,
2222 JNI::SetBooleanField,
2223 JNI::SetByteField,
2224 JNI::SetCharField,
2225 JNI::SetShortField,
2226 JNI::SetIntField,
2227 JNI::SetLongField,
2228 JNI::SetFloatField,
2229 JNI::SetDoubleField,
2230 JNI::GetStaticMethodID,
2231 JNI::CallStaticObjectMethod,
2232 JNI::CallStaticObjectMethodV,
2233 JNI::CallStaticObjectMethodA,
2234 JNI::CallStaticBooleanMethod,
2235 JNI::CallStaticBooleanMethodV,
2236 JNI::CallStaticBooleanMethodA,
2237 JNI::CallStaticByteMethod,
2238 JNI::CallStaticByteMethodV,
2239 JNI::CallStaticByteMethodA,
2240 JNI::CallStaticCharMethod,
2241 JNI::CallStaticCharMethodV,
2242 JNI::CallStaticCharMethodA,
2243 JNI::CallStaticShortMethod,
2244 JNI::CallStaticShortMethodV,
2245 JNI::CallStaticShortMethodA,
2246 JNI::CallStaticIntMethod,
2247 JNI::CallStaticIntMethodV,
2248 JNI::CallStaticIntMethodA,
2249 JNI::CallStaticLongMethod,
2250 JNI::CallStaticLongMethodV,
2251 JNI::CallStaticLongMethodA,
2252 JNI::CallStaticFloatMethod,
2253 JNI::CallStaticFloatMethodV,
2254 JNI::CallStaticFloatMethodA,
2255 JNI::CallStaticDoubleMethod,
2256 JNI::CallStaticDoubleMethodV,
2257 JNI::CallStaticDoubleMethodA,
2258 JNI::CallStaticVoidMethod,
2259 JNI::CallStaticVoidMethodV,
2260 JNI::CallStaticVoidMethodA,
2261 JNI::GetStaticFieldID,
2262 JNI::GetStaticObjectField,
2263 JNI::GetStaticBooleanField,
2264 JNI::GetStaticByteField,
2265 JNI::GetStaticCharField,
2266 JNI::GetStaticShortField,
2267 JNI::GetStaticIntField,
2268 JNI::GetStaticLongField,
2269 JNI::GetStaticFloatField,
2270 JNI::GetStaticDoubleField,
2271 JNI::SetStaticObjectField,
2272 JNI::SetStaticBooleanField,
2273 JNI::SetStaticByteField,
2274 JNI::SetStaticCharField,
2275 JNI::SetStaticShortField,
2276 JNI::SetStaticIntField,
2277 JNI::SetStaticLongField,
2278 JNI::SetStaticFloatField,
2279 JNI::SetStaticDoubleField,
2280 JNI::NewString,
2281 JNI::GetStringLength,
2282 JNI::GetStringChars,
2283 JNI::ReleaseStringChars,
2284 JNI::NewStringUTF,
2285 JNI::GetStringUTFLength,
2286 JNI::GetStringUTFChars,
2287 JNI::ReleaseStringUTFChars,
2288 JNI::GetArrayLength,
2289 JNI::NewObjectArray,
2290 JNI::GetObjectArrayElement,
2291 JNI::SetObjectArrayElement,
2292 JNI::NewBooleanArray,
2293 JNI::NewByteArray,
2294 JNI::NewCharArray,
2295 JNI::NewShortArray,
2296 JNI::NewIntArray,
2297 JNI::NewLongArray,
2298 JNI::NewFloatArray,
2299 JNI::NewDoubleArray,
2300 JNI::GetBooleanArrayElements,
2301 JNI::GetByteArrayElements,
2302 JNI::GetCharArrayElements,
2303 JNI::GetShortArrayElements,
2304 JNI::GetIntArrayElements,
2305 JNI::GetLongArrayElements,
2306 JNI::GetFloatArrayElements,
2307 JNI::GetDoubleArrayElements,
2308 JNI::ReleaseBooleanArrayElements,
2309 JNI::ReleaseByteArrayElements,
2310 JNI::ReleaseCharArrayElements,
2311 JNI::ReleaseShortArrayElements,
2312 JNI::ReleaseIntArrayElements,
2313 JNI::ReleaseLongArrayElements,
2314 JNI::ReleaseFloatArrayElements,
2315 JNI::ReleaseDoubleArrayElements,
2316 JNI::GetBooleanArrayRegion,
2317 JNI::GetByteArrayRegion,
2318 JNI::GetCharArrayRegion,
2319 JNI::GetShortArrayRegion,
2320 JNI::GetIntArrayRegion,
2321 JNI::GetLongArrayRegion,
2322 JNI::GetFloatArrayRegion,
2323 JNI::GetDoubleArrayRegion,
2324 JNI::SetBooleanArrayRegion,
2325 JNI::SetByteArrayRegion,
2326 JNI::SetCharArrayRegion,
2327 JNI::SetShortArrayRegion,
2328 JNI::SetIntArrayRegion,
2329 JNI::SetLongArrayRegion,
2330 JNI::SetFloatArrayRegion,
2331 JNI::SetDoubleArrayRegion,
2332 JNI::RegisterNatives,
2333 JNI::UnregisterNatives,
2334 JNI::MonitorEnter,
2335 JNI::MonitorExit,
2336 JNI::GetJavaVM,
2337 JNI::GetStringRegion,
2338 JNI::GetStringUTFRegion,
2339 JNI::GetPrimitiveArrayCritical,
2340 JNI::ReleasePrimitiveArrayCritical,
2341 JNI::GetStringCritical,
2342 JNI::ReleaseStringCritical,
2343 JNI::NewWeakGlobalRef,
2344 JNI::DeleteWeakGlobalRef,
2345 JNI::ExceptionCheck,
2346 JNI::NewDirectByteBuffer,
2347 JNI::GetDirectBufferAddress,
2348 JNI::GetDirectBufferCapacity,
2349 JNI::GetObjectRefType,
Carl Shapiroea4dca82011-08-01 13:45:38 -07002350};
2351
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002352static const size_t kMonitorsInitial = 32; // Arbitrary.
2353static const size_t kMonitorsMax = 4096; // Arbitrary sanity check.
2354
2355static const size_t kLocalsInitial = 64; // Arbitrary.
2356static const size_t kLocalsMax = 512; // Arbitrary sanity check.
Elliott Hughesbbd76712011-08-17 10:25:24 -07002357
Elliott Hughes515a5bc2011-08-17 11:08:34 -07002358JNIEnvExt::JNIEnvExt(Thread* self, bool check_jni)
Elliott Hughesbbd76712011-08-17 10:25:24 -07002359 : fns(&gNativeInterface),
2360 self(self),
Elliott Hughes515a5bc2011-08-17 11:08:34 -07002361 check_jni(check_jni),
Elliott Hughesbbd76712011-08-17 10:25:24 -07002362 critical(false),
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002363 monitors("monitors", kMonitorsInitial, kMonitorsMax),
2364 locals(kLocalsInitial, kLocalsMax, kLocal) {
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002365}
2366
Carl Shapiroea4dca82011-08-01 13:45:38 -07002367// JNI Invocation interface.
2368
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002369extern "C" jint JNI_CreateJavaVM(JavaVM** p_vm, void** p_env, void* vm_args) {
2370 const JavaVMInitArgs* args = static_cast<JavaVMInitArgs*>(vm_args);
2371 if (args->version < JNI_VERSION_1_2) {
2372 return JNI_EVERSION;
2373 }
2374 Runtime::Options options;
2375 for (int i = 0; i < args->nOptions; ++i) {
2376 JavaVMOption* option = &args->options[i];
Carl Shapirofc322c72011-07-27 00:20:01 -07002377 options.push_back(std::make_pair(StringPiece(option->optionString),
2378 option->extraInfo));
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002379 }
2380 bool ignore_unrecognized = args->ignoreUnrecognized;
Elliott Hughesf2682d52011-08-15 16:37:04 -07002381 Runtime* runtime = Runtime::Create(options, ignore_unrecognized);
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002382 if (runtime == NULL) {
2383 return JNI_ERR;
2384 } else {
2385 *p_env = reinterpret_cast<JNIEnv*>(Thread::Current()->GetJniEnv());
Elliott Hughes0af55432011-08-17 18:37:28 -07002386 *p_vm = reinterpret_cast<JavaVM*>(runtime->GetJavaVM());
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002387 return JNI_OK;
2388 }
2389}
2390
Elliott Hughesf2682d52011-08-15 16:37:04 -07002391extern "C" jint JNI_GetCreatedJavaVMs(JavaVM** vms, jsize, jsize* vm_count) {
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002392 Runtime* runtime = Runtime::Current();
2393 if (runtime == NULL) {
Elliott Hughesf2682d52011-08-15 16:37:04 -07002394 *vm_count = 0;
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002395 } else {
Elliott Hughesf2682d52011-08-15 16:37:04 -07002396 *vm_count = 1;
Elliott Hughes0af55432011-08-17 18:37:28 -07002397 vms[0] = reinterpret_cast<JavaVM*>(runtime->GetJavaVM());
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002398 }
2399 return JNI_OK;
2400}
2401
2402// Historically unsupported.
2403extern "C" jint JNI_GetDefaultJavaVMInitArgs(void* vm_args) {
2404 return JNI_ERR;
2405}
2406
Elliott Hughescdf53122011-08-19 15:46:09 -07002407class JII {
2408 public:
2409 static jint DestroyJavaVM(JavaVM* vm) {
2410 if (vm == NULL) {
2411 return JNI_ERR;
2412 } else {
2413 JavaVMExt* raw_vm = reinterpret_cast<JavaVMExt*>(vm);
2414 delete raw_vm->runtime;
2415 return JNI_OK;
2416 }
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002417 }
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002418
Elliott Hughescdf53122011-08-19 15:46:09 -07002419 static jint AttachCurrentThread(JavaVM* vm, JNIEnv** p_env, void* thr_args) {
2420 if (vm == NULL || p_env == NULL) {
2421 return JNI_ERR;
2422 }
Elliott Hughesf2682d52011-08-15 16:37:04 -07002423 JavaVMExt* raw_vm = reinterpret_cast<JavaVMExt*>(vm);
2424 Runtime* runtime = raw_vm->runtime;
Elliott Hughescdf53122011-08-19 15:46:09 -07002425 const char* name = NULL;
2426 if (thr_args != NULL) {
2427 // TODO: check version
2428 name = static_cast<JavaVMAttachArgs*>(thr_args)->name;
2429 // TODO: thread group
2430 }
2431 bool success = runtime->AttachCurrentThread(name, p_env);
2432 if (!success) {
2433 return JNI_ERR;
2434 } else {
2435 return JNI_OK;
2436 }
2437 }
2438
2439 static jint AttachCurrentThreadAsDaemon(JavaVM* vm, JNIEnv** p_env, void* thr_args) {
2440 if (vm == NULL || p_env == NULL) {
2441 return JNI_ERR;
2442 }
2443 JavaVMExt* raw_vm = reinterpret_cast<JavaVMExt*>(vm);
2444 Runtime* runtime = raw_vm->runtime;
2445 const char* name = NULL;
2446 if (thr_args != NULL) {
2447 // TODO: check version
2448 name = static_cast<JavaVMAttachArgs*>(thr_args)->name;
2449 // TODO: thread group
2450 }
2451 bool success = runtime->AttachCurrentThreadAsDaemon(name, p_env);
2452 if (!success) {
2453 return JNI_ERR;
2454 } else {
2455 return JNI_OK;
2456 }
2457 }
2458
2459 static jint DetachCurrentThread(JavaVM* vm) {
2460 if (vm == NULL) {
2461 return JNI_ERR;
2462 } else {
2463 JavaVMExt* raw_vm = reinterpret_cast<JavaVMExt*>(vm);
2464 Runtime* runtime = raw_vm->runtime;
2465 runtime->DetachCurrentThread();
2466 return JNI_OK;
2467 }
2468 }
2469
2470 static jint GetEnv(JavaVM* vm, void** env, jint version) {
2471 if (version < JNI_VERSION_1_1 || version > JNI_VERSION_1_6) {
2472 return JNI_EVERSION;
2473 }
2474 if (vm == NULL || env == NULL) {
2475 return JNI_ERR;
2476 }
2477 Thread* thread = Thread::Current();
2478 if (thread == NULL) {
2479 *env = NULL;
2480 return JNI_EDETACHED;
2481 }
2482 *env = thread->GetJniEnv();
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002483 return JNI_OK;
2484 }
Elliott Hughescdf53122011-08-19 15:46:09 -07002485};
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002486
Elliott Hughesf2682d52011-08-15 16:37:04 -07002487struct JNIInvokeInterface gInvokeInterface = {
Carl Shapiroea4dca82011-08-01 13:45:38 -07002488 NULL, // reserved0
2489 NULL, // reserved1
2490 NULL, // reserved2
Elliott Hughescdf53122011-08-19 15:46:09 -07002491 JII::DestroyJavaVM,
2492 JII::AttachCurrentThread,
2493 JII::DetachCurrentThread,
2494 JII::GetEnv,
2495 JII::AttachCurrentThreadAsDaemon
Carl Shapiroea4dca82011-08-01 13:45:38 -07002496};
2497
Elliott Hughesbbd76712011-08-17 10:25:24 -07002498static const size_t kPinTableInitialSize = 16;
2499static const size_t kPinTableMaxSize = 1024;
2500
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002501static const size_t kGlobalsInitial = 512; // Arbitrary.
2502static const size_t kGlobalsMax = 51200; // Arbitrary sanity check.
2503
2504static const size_t kWeakGlobalsInitial = 16; // Arbitrary.
2505static const size_t kWeakGlobalsMax = 51200; // Arbitrary sanity check.
2506
Elliott Hughes0af55432011-08-17 18:37:28 -07002507JavaVMExt::JavaVMExt(Runtime* runtime, bool check_jni, bool verbose_jni)
Elliott Hughesbbd76712011-08-17 10:25:24 -07002508 : fns(&gInvokeInterface),
2509 runtime(runtime),
Elliott Hughes515a5bc2011-08-17 11:08:34 -07002510 check_jni(check_jni),
Elliott Hughes0af55432011-08-17 18:37:28 -07002511 verbose_jni(verbose_jni),
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002512 pin_table("pin table", kPinTableInitialSize, kPinTableMaxSize),
Elliott Hughes18c07532011-08-18 15:50:51 -07002513 globals_lock(Mutex::Create("JNI global reference table lock")),
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002514 globals(kGlobalsInitial, kGlobalsMax, kGlobal),
Elliott Hughes18c07532011-08-18 15:50:51 -07002515 weak_globals_lock(Mutex::Create("JNI weak global reference table lock")),
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002516 weak_globals(kWeakGlobalsInitial, kWeakGlobalsMax, kWeakGlobal) {
Elliott Hughesf2682d52011-08-15 16:37:04 -07002517}
2518
Elliott Hughesde69d7f2011-08-18 16:49:37 -07002519JavaVMExt::~JavaVMExt() {
2520 delete globals_lock;
2521 delete weak_globals_lock;
2522}
2523
Elliott Hughescdf53122011-08-19 15:46:09 -07002524/*
2525 * Load native code from the specified absolute pathname. Per the spec,
2526 * if we've already loaded a library with the specified pathname, we
2527 * return without doing anything.
2528 *
2529 * TODO? for better results we should absolutify the pathname. For fully
2530 * correct results we should stat to get the inode and compare that. The
2531 * existing implementation is fine so long as everybody is using
2532 * System.loadLibrary.
2533 *
2534 * The library will be associated with the specified class loader. The JNI
2535 * spec says we can't load the same library into more than one class loader.
2536 *
2537 * Returns "true" on success. On failure, sets *detail to a
2538 * human-readable description of the error or NULL if no detail is
2539 * available; ownership of the string is transferred to the caller.
2540 */
2541bool JavaVMExt::LoadNativeLibrary(const std::string& path, Object* class_loader, char** detail) {
2542 *detail = NULL;
2543
2544 // See if we've already loaded this library. If we have, and the class loader
2545 // matches, return successfully without doing anything.
2546 SharedLibrary* library = libraries[path];
2547 if (library != NULL) {
2548 if (library->GetClassLoader() != class_loader) {
2549 LOG(WARNING) << "Shared library \"" << path << "\" already opened by "
2550 << "ClassLoader " << library->GetClassLoader() << "; "
2551 << "can't open in " << class_loader;
2552 *detail = strdup("already opened by different ClassLoader");
2553 return false;
2554 }
2555 if (verbose_jni) {
2556 LOG(INFO) << "[Shared library \"" << path << "\" already loaded in "
2557 << "ClassLoader " << class_loader << "]";
2558 }
2559 if (!library->CheckOnLoadResult(this)) {
2560 *detail = strdup("JNI_OnLoad failed before");
2561 return false;
2562 }
2563 return true;
2564 }
2565
2566 // Open the shared library. Because we're using a full path, the system
2567 // doesn't have to search through LD_LIBRARY_PATH. (It may do so to
2568 // resolve this library's dependencies though.)
2569
2570 // Failures here are expected when java.library.path has several entries
2571 // and we have to hunt for the lib.
2572
2573 // The current version of the dynamic linker prints detailed information
2574 // about dlopen() failures. Some things to check if the message is
2575 // cryptic:
2576 // - make sure the library exists on the device
2577 // - verify that the right path is being opened (the debug log message
2578 // above can help with that)
2579 // - check to see if the library is valid (e.g. not zero bytes long)
2580 // - check config/prelink-linux-arm.map to ensure that the library
2581 // is listed and is not being overrun by the previous entry (if
2582 // loading suddenly stops working on a prelinked library, this is
2583 // a good one to check)
2584 // - write a trivial app that calls sleep() then dlopen(), attach
2585 // to it with "strace -p <pid>" while it sleeps, and watch for
2586 // attempts to open nonexistent dependent shared libs
2587
2588 // TODO: automate some of these checks!
2589
2590 // This can execute slowly for a large library on a busy system, so we
2591 // want to switch from RUNNING to VMWAIT while it executes. This allows
2592 // the GC to ignore us.
2593 Thread* self = Thread::Current();
2594 Thread::State old_state = self->GetState();
2595 self->SetState(Thread::kWaiting); // TODO: VMWAIT
2596 void* handle = dlopen(path.c_str(), RTLD_LAZY);
2597 self->SetState(old_state);
2598
2599 if (verbose_jni) {
2600 LOG(INFO) << "[Call to dlopen(\"" << path << "\") returned " << handle << "]";
2601 }
2602
2603 if (handle == NULL) {
2604 *detail = strdup(dlerror());
2605 return false;
2606 }
2607
2608 // Create a new entry.
2609 library = new SharedLibrary(path, handle, class_loader);
2610 UNIMPLEMENTED(ERROR) << "missing pthread_cond_init";
2611 // pthread_cond_init(&library->onLoadCond, NULL);
2612
2613 libraries[path] = library;
2614
2615 // if (pNewEntry != pActualEntry) {
2616 // LOG(INFO) << "WOW: we lost a race to add a shared library (\"" << path << "\" ClassLoader=" << class_loader <<")";
2617 // freeSharedLibEntry(pNewEntry);
2618 // return CheckOnLoadResult(this, pActualEntry);
2619 // } else
2620 {
2621 if (verbose_jni) {
2622 LOG(INFO) << "[Added shared library \"" << path << "\" for ClassLoader " << class_loader << "]";
2623 }
2624
2625 bool result = true;
2626 void* sym = dlsym(handle, "JNI_OnLoad");
2627 if (sym == NULL) {
2628 if (verbose_jni) {
2629 LOG(INFO) << "[No JNI_OnLoad found in \"" << path << "\"]";
2630 }
2631 } else {
2632 // Call JNI_OnLoad. We have to override the current class
2633 // loader, which will always be "null" since the stuff at the
2634 // top of the stack is around Runtime.loadLibrary(). (See
2635 // the comments in the JNI FindClass function.)
2636 UNIMPLEMENTED(WARNING) << "need to override current class loader";
2637 typedef int (*JNI_OnLoadFn)(JavaVM*, void*);
2638 JNI_OnLoadFn jni_on_load = reinterpret_cast<JNI_OnLoadFn>(sym);
2639 //Object* prevOverride = self->classLoaderOverride;
2640 //self->classLoaderOverride = classLoader;
2641
2642 old_state = self->GetState();
2643 self->SetState(Thread::kNative);
2644 if (verbose_jni) {
2645 LOG(INFO) << "[Calling JNI_OnLoad in \"" << path << "\"]";
2646 }
2647 int version = (*jni_on_load)(reinterpret_cast<JavaVM*>(this), NULL);
2648 self->SetState(old_state);
2649
2650 UNIMPLEMENTED(WARNING) << "need to restore current class loader";
2651 //self->classLoaderOverride = prevOverride;
2652
2653 if (version != JNI_VERSION_1_2 &&
2654 version != JNI_VERSION_1_4 &&
2655 version != JNI_VERSION_1_6) {
2656 LOG(WARNING) << "JNI_OnLoad in \"" << path << "\" returned "
2657 << "bad version: " << version;
2658 // It's unwise to call dlclose() here, but we can mark it
2659 // as bad and ensure that future load attempts will fail.
2660 // We don't know how far JNI_OnLoad got, so there could
2661 // be some partially-initialized stuff accessible through
2662 // newly-registered native method calls. We could try to
2663 // unregister them, but that doesn't seem worthwhile.
2664 result = false;
2665 } else {
2666 if (verbose_jni) {
2667 LOG(INFO) << "[Returned " << (result ? "successfully" : "failure")
2668 << " from JNI_OnLoad in \"" << path << "\"]";
2669 }
2670 }
2671 }
2672
2673 library->SetResult(result);
2674 return result;
2675 }
2676}
2677
Ian Rogersdf20fe02011-07-20 20:34:16 -07002678} // namespace art