blob: f28bff94a01ccfb6d44c65e7ddd5d531aad1ff89 [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
Ian Rogerscdd1d2d2011-08-18 09:58:17 -070023jobject NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args);
24void CallNonvirtualVoidMethodV(JNIEnv* env, jobject obj, jclass clazz,
25 jmethodID methodID, va_list args);
26void CallNonvirtualVoidMethodA(JNIEnv* env, jobject obj, jclass clazz,
27 jmethodID methodID, jvalue* args);
28
Elliott Hughes0af55432011-08-17 18:37:28 -070029enum JNI_OnLoadState {
30 kPending = 0, /* initial state, must be zero */
31 kFailed,
32 kOkay,
33};
34
35struct SharedLibrary {
Elliott Hughes18c07532011-08-18 15:50:51 -070036 SharedLibrary() : jni_on_load_lock(Mutex::Create("JNI_OnLoad lock")) {
37 }
38
39 ~SharedLibrary() {
40 delete jni_on_load_lock;
Elliott Hughes0af55432011-08-17 18:37:28 -070041 }
42
43 // Path to library "/system/lib/libjni.so".
44 std::string path;
45
46 // The void* returned by dlopen(3).
47 void* handle;
48
49 // The ClassLoader this library is associated with.
50 Object* class_loader;
51
52 // Guards remaining items.
Elliott Hughes18c07532011-08-18 15:50:51 -070053 Mutex* jni_on_load_lock;
Elliott Hughes0af55432011-08-17 18:37:28 -070054 // Wait for JNI_OnLoad in other thread.
55 pthread_cond_t jni_on_load_cond;
56 // Recursive invocation guard.
57 uint32_t jni_on_load_tid;
58 // Result of earlier JNI_OnLoad call.
59 JNI_OnLoadState jni_on_load_result;
60};
61
62/*
63 * Check the result of an earlier call to JNI_OnLoad on this library. If
64 * the call has not yet finished in another thread, wait for it.
65 */
66bool CheckOnLoadResult(JavaVMExt* vm, SharedLibrary* library) {
67 Thread* self = Thread::Current();
68 if (library->jni_on_load_tid == self->GetId()) {
69 // Check this so we don't end up waiting for ourselves. We need
70 // to return "true" so the caller can continue.
71 LOG(INFO) << *self << " recursive attempt to load library "
72 << "\"" << library->path << "\"";
73 return true;
74 }
75
76 UNIMPLEMENTED(ERROR) << "need to pthread_cond_wait!";
Elliott Hughes18c07532011-08-18 15:50:51 -070077 // MutexLock mu(library->jni_on_load_lock);
Elliott Hughes0af55432011-08-17 18:37:28 -070078 while (library->jni_on_load_result == kPending) {
79 if (vm->verbose_jni) {
80 LOG(INFO) << "[" << *self << " waiting for \"" << library->path << "\" "
81 << "JNI_OnLoad...]";
82 }
83 Thread::State old_state = self->GetState();
84 self->SetState(Thread::kWaiting); // TODO: VMWAIT
85 // pthread_cond_wait(&library->jni_on_load_cond, &library->jni_on_load_lock);
86 self->SetState(old_state);
87 }
88
89 bool okay = (library->jni_on_load_result == kOkay);
90 if (vm->verbose_jni) {
91 LOG(INFO) << "[Earlier JNI_OnLoad for \"" << library->path << "\" "
92 << (okay ? "succeeded" : "failed") << "]";
93 }
94 return okay;
95}
96
97typedef int (*JNI_OnLoadFn)(JavaVM*, void*);
98
99/*
100 * Load native code from the specified absolute pathname. Per the spec,
101 * if we've already loaded a library with the specified pathname, we
102 * return without doing anything.
103 *
104 * TODO? for better results we should absolutify the pathname. For fully
105 * correct results we should stat to get the inode and compare that. The
106 * existing implementation is fine so long as everybody is using
107 * System.loadLibrary.
108 *
109 * The library will be associated with the specified class loader. The JNI
110 * spec says we can't load the same library into more than one class loader.
111 *
112 * Returns "true" on success. On failure, sets *detail to a
113 * human-readable description of the error or NULL if no detail is
114 * available; ownership of the string is transferred to the caller.
115 */
116bool JavaVMExt::LoadNativeLibrary(const std::string& path, Object* class_loader, char** detail) {
117 *detail = NULL;
118
119 // See if we've already loaded this library. If we have, and the class loader
120 // matches, return successfully without doing anything.
121 SharedLibrary* library = libraries[path];
122 if (library != NULL) {
123 if (library->class_loader != class_loader) {
124 LOG(WARNING) << "Shared library \"" << path << "\" already opened by "
125 << "ClassLoader " << library->class_loader << "; "
126 << "can't open in " << class_loader;
127 *detail = strdup("already opened by different ClassLoader");
128 return false;
129 }
130 if (verbose_jni) {
131 LOG(INFO) << "[Shared library \"" << path << "\" already loaded in "
132 << "ClassLoader " << class_loader << "]";
133 }
134 if (!CheckOnLoadResult(this, library)) {
135 *detail = strdup("JNI_OnLoad failed before");
136 return false;
137 }
138 return true;
139 }
140
141 // Open the shared library. Because we're using a full path, the system
142 // doesn't have to search through LD_LIBRARY_PATH. (It may do so to
143 // resolve this library's dependencies though.)
144
145 // Failures here are expected when java.library.path has several entries
146 // and we have to hunt for the lib.
147
148 // The current version of the dynamic linker prints detailed information
149 // about dlopen() failures. Some things to check if the message is
150 // cryptic:
151 // - make sure the library exists on the device
152 // - verify that the right path is being opened (the debug log message
153 // above can help with that)
154 // - check to see if the library is valid (e.g. not zero bytes long)
155 // - check config/prelink-linux-arm.map to ensure that the library
156 // is listed and is not being overrun by the previous entry (if
157 // loading suddenly stops working on a prelinked library, this is
158 // a good one to check)
159 // - write a trivial app that calls sleep() then dlopen(), attach
160 // to it with "strace -p <pid>" while it sleeps, and watch for
161 // attempts to open nonexistent dependent shared libs
162
163 // TODO: automate some of these checks!
164
Elliott Hughes0af55432011-08-17 18:37:28 -0700165 // This can execute slowly for a large library on a busy system, so we
166 // want to switch from RUNNING to VMWAIT while it executes. This allows
167 // the GC to ignore us.
168 Thread* self = Thread::Current();
169 Thread::State old_state = self->GetState();
170 self->SetState(Thread::kWaiting); // TODO: VMWAIT
171 void* handle = dlopen(path.c_str(), RTLD_LAZY);
172 self->SetState(old_state);
173
174 if (verbose_jni) {
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700175 LOG(INFO) << "[Call to dlopen(\"" << path << "\") returned " << handle << "]";
Elliott Hughes0af55432011-08-17 18:37:28 -0700176 }
177
178 if (handle == NULL) {
179 *detail = strdup(dlerror());
180 return false;
181 }
182
183 // Create a new entry.
184 library = new SharedLibrary;
185 library->path = path;
186 library->handle = handle;
187 library->class_loader = class_loader;
188 UNIMPLEMENTED(ERROR) << "missing pthread_cond_init";
189 // pthread_cond_init(&library->onLoadCond, NULL);
190 library->jni_on_load_tid = self->GetId();
191
192 libraries[path] = library;
193
194// if (pNewEntry != pActualEntry) {
195// LOG(INFO) << "WOW: we lost a race to add a shared library (\"" << path << "\" ClassLoader=" << class_loader <<")";
196// freeSharedLibEntry(pNewEntry);
197// return CheckOnLoadResult(this, pActualEntry);
198// } else
199 {
200 if (verbose_jni) {
201 LOG(INFO) << "[Added shared library \"" << path << "\" for ClassLoader " << class_loader << "]";
202 }
203
204 bool result = true;
205 void* sym = dlsym(handle, "JNI_OnLoad");
206 if (sym == NULL) {
207 if (verbose_jni) {
208 LOG(INFO) << "[No JNI_OnLoad found in \"" << path << "\"]";
209 }
210 } else {
211 // Call JNI_OnLoad. We have to override the current class
212 // loader, which will always be "null" since the stuff at the
213 // top of the stack is around Runtime.loadLibrary(). (See
214 // the comments in the JNI FindClass function.)
215 UNIMPLEMENTED(WARNING) << "need to override current class loader";
216 JNI_OnLoadFn jni_on_load = reinterpret_cast<JNI_OnLoadFn>(sym);
217 //Object* prevOverride = self->classLoaderOverride;
218 //self->classLoaderOverride = classLoader;
219
220 old_state = self->GetState();
221 self->SetState(Thread::kNative);
222 if (verbose_jni) {
223 LOG(INFO) << "[Calling JNI_OnLoad in \"" << path << "\"]";
224 }
225 int version = (*jni_on_load)(reinterpret_cast<JavaVM*>(this), NULL);
226 self->SetState(old_state);
227
228 UNIMPLEMENTED(WARNING) << "need to restore current class loader";
229 //self->classLoaderOverride = prevOverride;
230
231 if (version != JNI_VERSION_1_2 &&
232 version != JNI_VERSION_1_4 &&
233 version != JNI_VERSION_1_6) {
234 LOG(WARNING) << "JNI_OnLoad in \"" << path << "\" returned "
235 << "bad version: " << version;
236 // It's unwise to call dlclose() here, but we can mark it
237 // as bad and ensure that future load attempts will fail.
238 // We don't know how far JNI_OnLoad got, so there could
239 // be some partially-initialized stuff accessible through
240 // newly-registered native method calls. We could try to
241 // unregister them, but that doesn't seem worthwhile.
242 result = false;
243 } else {
244 if (verbose_jni) {
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700245 LOG(INFO) << "[Returned " << (result ? "successfully" : "failure")
246 << " from JNI_OnLoad in \"" << path << "\"]";
Elliott Hughes0af55432011-08-17 18:37:28 -0700247 }
248 }
249 }
250
251 library->jni_on_load_result = result ? kOkay : kFailed;
252 library->jni_on_load_tid = 0;
253
254 // Broadcast a wakeup to anybody sleeping on the condition variable.
255 UNIMPLEMENTED(ERROR) << "missing pthread_cond_broadcast";
Elliott Hughes18c07532011-08-18 15:50:51 -0700256 // MutexLock mu(library->jni_on_load_lock);
Elliott Hughes0af55432011-08-17 18:37:28 -0700257 // pthread_cond_broadcast(&library->jni_on_load_cond);
258 return result;
259 }
260}
261
Elliott Hughes22f40932011-08-12 13:06:37 -0700262// Entry/exit processing for all JNI calls.
263//
264// This performs the necessary thread state switching, lets us amortize the
265// cost of working out the current thread, and lets us check (and repair) apps
266// that are using a JNIEnv on the wrong thread.
267class ScopedJniThreadState {
268 public:
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700269 explicit ScopedJniThreadState(JNIEnv* env)
270 : env_(reinterpret_cast<JNIEnvExt*>(env)) {
Elliott Hughesb20a5542011-08-12 18:03:12 -0700271 self_ = ThreadForEnv(env);
Elliott Hughes22f40932011-08-12 13:06:37 -0700272 self_->SetState(Thread::kRunnable);
273 }
274
275 ~ScopedJniThreadState() {
276 self_->SetState(Thread::kNative);
277 }
278
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700279 JNIEnvExt* Env() {
280 return env_;
281 }
282
Elliott Hughesb20a5542011-08-12 18:03:12 -0700283 Thread* Self() {
Elliott Hughes22f40932011-08-12 13:06:37 -0700284 return self_;
285 }
286
Elliott Hughesb20a5542011-08-12 18:03:12 -0700287 private:
288 static Thread* ThreadForEnv(JNIEnv* env) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700289 // TODO: need replacement for gDvmJni.
290 bool workAroundAppJniBugs = true;
291 Thread* env_self = reinterpret_cast<JNIEnvExt*>(env)->self;
292 Thread* self = workAroundAppJniBugs ? Thread::Current() : env_self;
293 if (self != env_self) {
Elliott Hughes330304d2011-08-12 14:28:05 -0700294 LOG(ERROR) << "JNI ERROR: JNIEnv for " << *env_self
295 << " used on " << *self;
296 // TODO: dump stack
Elliott Hughes22f40932011-08-12 13:06:37 -0700297 }
298 return self;
299 }
300
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700301 JNIEnvExt* env_;
Elliott Hughes22f40932011-08-12 13:06:37 -0700302 Thread* self_;
303 DISALLOW_COPY_AND_ASSIGN(ScopedJniThreadState);
304};
305
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700306/*
307 * Add a local reference for an object to the current stack frame. When
308 * the native function returns, the reference will be discarded.
309 *
310 * We need to allow the same reference to be added multiple times.
311 *
312 * This will be called on otherwise unreferenced objects. We cannot do
313 * GC allocations here, and it's best if we don't grab a mutex.
314 *
315 * Returns the local reference (currently just the same pointer that was
316 * passed in), or NULL on failure.
317 */
Elliott Hughes8a26c5c2011-08-15 18:35:43 -0700318template<typename T>
319T AddLocalReference(ScopedJniThreadState& ts, Object* obj) {
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700320 if (obj == NULL) {
321 return NULL;
322 }
323
324 IndirectReferenceTable& locals = ts.Env()->locals;
325
326 uint32_t cookie = IRT_FIRST_SEGMENT; // TODO
327 IndirectRef ref = locals.Add(cookie, obj);
328 if (ref == NULL) {
329 // TODO: just change Add's DCHECK to CHECK and lose this?
330 locals.Dump();
331 LOG(FATAL) << "Failed adding to JNI local reference table "
332 << "(has " << locals.Capacity() << " entries)";
333 // TODO: dvmDumpThread(dvmThreadSelf(), false);
334 }
335
336#if 0 // TODO: fix this to understand PushLocalFrame, so we can turn it on.
337 if (ts.Env()->check_jni) {
338 size_t entry_count = locals.Capacity();
339 if (entry_count > 16) {
340 std::string class_name(PrettyDescriptor(obj->GetClass()->GetDescriptor()));
341 LOG(WARNING) << "Warning: more than 16 JNI local references: "
342 << entry_count << " (most recent was a " << class_name << ")";
343 locals.Dump();
344 // TODO: dvmDumpThread(dvmThreadSelf(), false);
345 // dvmAbort();
346 }
347 }
348#endif
349
350 if (false /*gDvmJni.workAroundAppJniBugs*/) { // TODO
351 // Hand out direct pointers to support broken old apps.
352 return reinterpret_cast<T>(obj);
353 }
354
355 return reinterpret_cast<T>(ref);
356}
357
358template<typename T>
359T Decode(ScopedJniThreadState& ts, jobject obj) {
360 if (obj == NULL) {
361 return NULL;
362 }
363
364 IndirectRef ref = reinterpret_cast<IndirectRef>(obj);
365 IndirectRefKind kind = GetIndirectRefKind(ref);
366 Object* result;
367 switch (kind) {
368 case kLocal:
369 {
370 IndirectReferenceTable& locals = ts.Env()->locals;
371 result = locals.Get(ref);
372 break;
373 }
374 case kGlobal:
375 {
376 JavaVMExt* vm = Runtime::Current()->GetJavaVM();
377 IndirectReferenceTable& globals = vm->globals;
Elliott Hughes18c07532011-08-18 15:50:51 -0700378 MutexLock mu(vm->globals_lock);
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700379 result = globals.Get(ref);
380 break;
381 }
382 case kWeakGlobal:
383 {
384 JavaVMExt* vm = Runtime::Current()->GetJavaVM();
385 IndirectReferenceTable& weak_globals = vm->weak_globals;
Elliott Hughes18c07532011-08-18 15:50:51 -0700386 MutexLock mu(vm->weak_globals_lock);
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700387 result = weak_globals.Get(ref);
388 if (result == kClearedJniWeakGlobal) {
389 // This is a special case where it's okay to return NULL.
390 return NULL;
391 }
392 break;
393 }
394 case kInvalid:
395 default:
396 if (false /*gDvmJni.workAroundAppJniBugs*/) { // TODO
397 // Assume an invalid local reference is actually a direct pointer.
398 return reinterpret_cast<T>(obj);
399 }
400 LOG(FATAL) << "Invalid indirect reference " << obj;
401 return reinterpret_cast<T>(kInvalidIndirectRefObject);
402 }
403
404 if (result == NULL) {
405 LOG(FATAL) << "JNI ERROR (app bug): use of deleted " << kind << ": "
406 << obj;
407 }
408 return reinterpret_cast<T>(result);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -0700409}
410
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700411void CreateInvokeStub(Assembler* assembler, Method* method);
412
413bool EnsureInvokeStub(Method* method) {
414 if (method->GetInvokeStub() != NULL) {
415 return true;
416 }
417 // TODO: use signature to find a matching stub
418 // TODO: failed, acquire a lock on the stub table
419 Assembler assembler;
420 CreateInvokeStub(&assembler, method);
421 // TODO: store native_entry in the stub table
422 int prot = PROT_READ | PROT_WRITE | PROT_EXEC;
423 size_t length = assembler.CodeSize();
424 void* addr = mmap(NULL, length, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
425 if (addr == MAP_FAILED) {
426 PLOG(FATAL) << "mmap failed";
427 }
428 MemoryRegion region(addr, length);
429 assembler.FinalizeInstructions(region);
430 method->SetInvokeStub(reinterpret_cast<Method::InvokeStub*>(region.pointer()));
431 return true;
432}
433
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700434byte* CreateArgArray(ScopedJniThreadState& ts, Method* method, va_list ap) {
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700435 size_t num_bytes = method->NumArgArrayBytes();
436 scoped_array<byte> arg_array(new byte[num_bytes]);
437 const StringPiece& shorty = method->GetShorty();
Ian Rogers4dd71f12011-08-16 14:16:02 -0700438 for (int i = 1, offset = 0; i < shorty.size(); ++i) {
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700439 switch (shorty[i]) {
440 case 'Z':
441 case 'B':
442 case 'C':
443 case 'S':
444 case 'I':
445 *reinterpret_cast<int32_t*>(&arg_array[offset]) = va_arg(ap, jint);
446 offset += 4;
447 break;
448 case 'F':
449 *reinterpret_cast<float*>(&arg_array[offset]) = va_arg(ap, jdouble);
450 offset += 4;
451 break;
452 case 'L': {
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700453 Object* obj = Decode<Object*>(ts, va_arg(ap, jobject));
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700454 *reinterpret_cast<Object**>(&arg_array[offset]) = obj;
455 offset += sizeof(Object*);
456 break;
457 }
458 case 'D':
459 *reinterpret_cast<double*>(&arg_array[offset]) = va_arg(ap, jdouble);
460 offset += 8;
461 break;
462 case 'J':
463 *reinterpret_cast<int64_t*>(&arg_array[offset]) = va_arg(ap, jlong);
464 offset += 8;
465 break;
466 }
467 }
468 return arg_array.release();
469}
470
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700471byte* CreateArgArray(ScopedJniThreadState& ts, Method* method, jvalue* args) {
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700472 size_t num_bytes = method->NumArgArrayBytes();
473 scoped_array<byte> arg_array(new byte[num_bytes]);
474 const StringPiece& shorty = method->GetShorty();
Ian Rogers4dd71f12011-08-16 14:16:02 -0700475 for (int i = 1, offset = 0; i < shorty.size(); ++i) {
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700476 switch (shorty[i]) {
477 case 'Z':
478 case 'B':
479 case 'C':
480 case 'S':
481 case 'I':
482 *reinterpret_cast<uint32_t*>(&arg_array[offset]) = args[i - 1].i;
483 offset += 4;
484 break;
485 case 'F':
486 *reinterpret_cast<float*>(&arg_array[offset]) = args[i - 1].f;
487 offset += 4;
488 break;
489 case 'L': {
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700490 Object* obj = Decode<Object*>(ts, args[i - 1].l);
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700491 *reinterpret_cast<Object**>(&arg_array[offset]) = obj;
492 offset += sizeof(Object*);
493 break;
494 }
495 case 'D':
496 *reinterpret_cast<double*>(&arg_array[offset]) = args[i - 1].d;
497 offset += 8;
498 break;
499 case 'J':
500 *reinterpret_cast<uint64_t*>(&arg_array[offset]) = args[i - 1].j;
501 offset += 8;
502 break;
503 }
504 }
505 return arg_array.release();
506}
507
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700508JValue InvokeWithArgArray(ScopedJniThreadState& ts, jobject obj,
509 jmethodID method_id, byte* args) {
Elliott Hughesf2682d52011-08-15 16:37:04 -0700510 // TODO: DecodeReference
511 Method* method = reinterpret_cast<Method*>(method_id);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700512 Object* rcvr = Decode<Object*>(ts, obj);
Ian Rogers6de08602011-08-19 14:52:39 -0700513 Thread* self = ts.Self();
514
515 // Push a transition back into managed code onto the linked list in thread
516 CHECK_EQ(Thread::kRunnable, self->GetState());
517 NativeToManagedRecord record;
518 self->PushNativeToManagedRecord(&record);
519
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700520 // Call the invoke stub associated with the method
521 // Pass everything as arguments
522 const Method::InvokeStub* stub = method->GetInvokeStub();
523 CHECK(stub != NULL);
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700524 JValue result;
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700525 // TODO: we should always have code associated with a method
526 if (method->GetCode()) {
Ian Rogers6de08602011-08-19 14:52:39 -0700527 (*stub)(method, rcvr, self, args, &result);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700528 } else {
529 // TODO: pretty print method here
530 LOG(WARNING) << "Not invoking method with no associated code";
531 result.j = 0;
532 }
Ian Rogers6de08602011-08-19 14:52:39 -0700533 // Pop transition
534 self->PopNativeToManagedRecord(record);
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700535 return result;
536}
537
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700538JValue InvokeWithJValues(ScopedJniThreadState& ts, jobject obj,
539 jmethodID method_id, jvalue* args) {
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700540 Method* method = reinterpret_cast<Method*>(method_id);
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700541 scoped_array<byte> arg_array(CreateArgArray(ts, method, args));
542 return InvokeWithArgArray(ts, obj, method_id, arg_array.get());
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700543}
544
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700545JValue InvokeWithVarArgs(ScopedJniThreadState& ts, jobject obj,
546 jmethodID method_id, va_list args) {
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700547 Method* method = reinterpret_cast<Method*>(method_id);
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700548 scoped_array<byte> arg_array(CreateArgArray(ts, method, args));
549 return InvokeWithArgArray(ts, obj, method_id, arg_array.get());
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700550}
551
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700552jint GetVersion(JNIEnv* env) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700553 ScopedJniThreadState ts(env);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700554 return JNI_VERSION_1_6;
555}
556
Elliott Hughesb20a5542011-08-12 18:03:12 -0700557jclass DefineClass(JNIEnv* env, const char*, jobject, const jbyte*, jsize) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700558 ScopedJniThreadState ts(env);
Elliott Hughesb20a5542011-08-12 18:03:12 -0700559 LOG(WARNING) << "JNI DefineClass is not supported";
Carl Shapiroea4dca82011-08-01 13:45:38 -0700560 return NULL;
561}
562
Elliott Hughes6b436852011-08-12 10:16:44 -0700563// Section 12.3.2 of the JNI spec describes JNI class descriptors. They're
564// separated with slashes but aren't wrapped with "L;" like regular descriptors
565// (i.e. "a/b/C" rather than "La/b/C;"). Arrays of reference types are an
566// exception; there the "L;" must be present ("[La/b/C;"). Historically we've
567// supported names with dots too (such as "a.b.C").
568std::string NormalizeJniClassDescriptor(const char* name) {
569 std::string result;
570 // Add the missing "L;" if necessary.
571 if (name[0] == '[') {
572 result = name;
573 } else {
574 result += 'L';
575 result += name;
576 result += ';';
577 }
578 // Rewrite '.' as '/' for backwards compatibility.
Elliott Hughesa5b897e2011-08-16 11:33:06 -0700579 if (result.find('.') != std::string::npos) {
580 LOG(WARNING) << "Call to JNI FindClass with dots in name: "
581 << "\"" << name << "\"";
582 std::replace(result.begin(), result.end(), '.', '/');
Elliott Hughes6b436852011-08-12 10:16:44 -0700583 }
584 return result;
585}
586
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700587jclass FindClass(JNIEnv* env, const char* name) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700588 ScopedJniThreadState ts(env);
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700589 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Elliott Hughes6b436852011-08-12 10:16:44 -0700590 std::string descriptor(NormalizeJniClassDescriptor(name));
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700591 // TODO: need to get the appropriate ClassLoader.
Elliott Hughes6b436852011-08-12 10:16:44 -0700592 Class* c = class_linker->FindClass(descriptor, NULL);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -0700593 return AddLocalReference<jclass>(ts, c);
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700594}
595
596jmethodID FromReflectedMethod(JNIEnv* env, jobject method) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700597 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700598 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700599 return NULL;
600}
601
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700602jfieldID FromReflectedField(JNIEnv* env, jobject field) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700603 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700604 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700605 return NULL;
606}
607
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700608jobject ToReflectedMethod(JNIEnv* env, jclass cls,
609 jmethodID methodID, jboolean isStatic) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700610 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700611 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700612 return NULL;
613}
614
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700615jclass GetSuperclass(JNIEnv* env, jclass sub) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700616 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700617 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700618 return NULL;
619}
620
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700621jboolean IsAssignableFrom(JNIEnv* env, jclass sub, jclass sup) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700622 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700623 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700624 return JNI_FALSE;
625}
626
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700627jobject ToReflectedField(JNIEnv* env, jclass cls,
628 jfieldID fieldID, jboolean isStatic) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700629 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700630 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700631 return NULL;
632}
633
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700634jint Throw(JNIEnv* env, jthrowable obj) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700635 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700636 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700637 return 0;
638}
639
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700640jint ThrowNew(JNIEnv* env, jclass clazz, const char* msg) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700641 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700642 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700643 return 0;
644}
645
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700646jthrowable ExceptionOccurred(JNIEnv* env) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700647 ScopedJniThreadState ts(env);
Ian Rogers4dd71f12011-08-16 14:16:02 -0700648 Object* exception = ts.Self()->GetException();
649 if (exception == NULL) {
650 return NULL;
651 } else {
652 // TODO: if adding a local reference failing causes the VM to abort
653 // then the following check will never occur.
654 jthrowable localException = AddLocalReference<jthrowable>(ts, exception);
655 if (localException == NULL) {
656 // We were unable to add a new local reference, and threw a new
657 // exception. We can't return "exception", because it's not a
658 // local reference. So we have to return NULL, indicating that
659 // there was no exception, even though it's pretty much raining
660 // exceptions in here.
661 LOG(WARNING) << "JNI WARNING: addLocal/exception combo";
662 }
663 return localException;
664 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700665}
666
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700667void ExceptionDescribe(JNIEnv* env) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700668 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700669 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700670}
671
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700672void ExceptionClear(JNIEnv* env) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700673 ScopedJniThreadState ts(env);
Elliott Hughesb20a5542011-08-12 18:03:12 -0700674 ts.Self()->ClearException();
Carl Shapiroea4dca82011-08-01 13:45:38 -0700675}
676
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700677void FatalError(JNIEnv* env, const char* msg) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700678 ScopedJniThreadState ts(env);
Elliott Hughesb20a5542011-08-12 18:03:12 -0700679 LOG(FATAL) << "JNI FatalError called: " << msg;
Carl Shapiroea4dca82011-08-01 13:45:38 -0700680}
681
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700682jint PushLocalFrame(JNIEnv* env, jint cap) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700683 ScopedJniThreadState ts(env);
Elliott Hughes0af55432011-08-17 18:37:28 -0700684 UNIMPLEMENTED(WARNING) << "ignoring PushLocalFrame(" << cap << ")";
685 return JNI_OK;
Carl Shapiroea4dca82011-08-01 13:45:38 -0700686}
687
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700688jobject PopLocalFrame(JNIEnv* env, jobject res) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700689 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700690 UNIMPLEMENTED(WARNING) << "ignoring PopLocalFrame " << res;
Elliott Hughes0af55432011-08-17 18:37:28 -0700691 return res;
Carl Shapiroea4dca82011-08-01 13:45:38 -0700692}
693
Elliott Hughes18c07532011-08-18 15:50:51 -0700694jobject NewGlobalRef(JNIEnv* env, jobject obj) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700695 ScopedJniThreadState ts(env);
Elliott Hughes18c07532011-08-18 15:50:51 -0700696 if (obj == NULL) {
697 return NULL;
698 }
699
700 JavaVMExt* vm = Runtime::Current()->GetJavaVM();
701 IndirectReferenceTable& globals = vm->globals;
702 MutexLock mu(vm->globals_lock);
703 IndirectRef ref = globals.Add(IRT_FIRST_SEGMENT, Decode<Object*>(ts, obj));
704 return reinterpret_cast<jobject>(ref);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700705}
706
Elliott Hughes18c07532011-08-18 15:50:51 -0700707void DeleteGlobalRef(JNIEnv* env, jobject obj) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700708 ScopedJniThreadState ts(env);
Elliott Hughes18c07532011-08-18 15:50:51 -0700709 if (obj == NULL) {
710 return;
711 }
712
713 JavaVMExt* vm = Runtime::Current()->GetJavaVM();
714 IndirectReferenceTable& globals = vm->globals;
715 MutexLock mu(vm->globals_lock);
716
717 if (!globals.Remove(IRT_FIRST_SEGMENT, obj)) {
718 LOG(WARNING) << "JNI WARNING: DeleteGlobalRef(" << obj << ") "
719 << "failed to find entry";
720 }
721}
722
723jweak NewWeakGlobalRef(JNIEnv* env, jobject obj) {
724 ScopedJniThreadState ts(env);
725 if (obj == NULL) {
726 return NULL;
727 }
728
729 JavaVMExt* vm = Runtime::Current()->GetJavaVM();
730 IndirectReferenceTable& weak_globals = vm->weak_globals;
731 MutexLock mu(vm->weak_globals_lock);
732 IndirectRef ref = weak_globals.Add(IRT_FIRST_SEGMENT, Decode<Object*>(ts, obj));
733 return reinterpret_cast<jobject>(ref);
734}
735
736void DeleteWeakGlobalRef(JNIEnv* env, jweak obj) {
737 ScopedJniThreadState ts(env);
738 if (obj == NULL) {
739 return;
740 }
741
742 JavaVMExt* vm = Runtime::Current()->GetJavaVM();
743 IndirectReferenceTable& weak_globals = vm->weak_globals;
744 MutexLock mu(vm->weak_globals_lock);
745
746 if (!weak_globals.Remove(IRT_FIRST_SEGMENT, obj)) {
747 LOG(WARNING) << "JNI WARNING: DeleteWeakGlobalRef(" << obj << ") "
748 << "failed to find entry";
749 }
750}
751
752jobject NewLocalRef(JNIEnv* env, jobject obj) {
753 ScopedJniThreadState ts(env);
754 if (obj == NULL) {
755 return NULL;
756 }
757
758 IndirectReferenceTable& locals = ts.Env()->locals;
759
760 uint32_t cookie = IRT_FIRST_SEGMENT; // TODO
761 IndirectRef ref = locals.Add(cookie, Decode<Object*>(ts, obj));
762 return reinterpret_cast<jobject>(ref);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700763}
764
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700765void DeleteLocalRef(JNIEnv* env, jobject obj) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700766 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700767 if (obj == NULL) {
768 return;
769 }
770
771 IndirectReferenceTable& locals = ts.Env()->locals;
772
773 uint32_t cookie = IRT_FIRST_SEGMENT; // TODO
774 if (!locals.Remove(cookie, obj)) {
775 // Attempting to delete a local reference that is not in the
776 // topmost local reference frame is a no-op. DeleteLocalRef returns
777 // void and doesn't throw any exceptions, but we should probably
778 // complain about it so the user will notice that things aren't
779 // going quite the way they expect.
780 LOG(WARNING) << "JNI WARNING: DeleteLocalRef(" << obj << ") "
781 << "failed to find entry";
782 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700783}
784
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700785jboolean IsSameObject(JNIEnv* env, jobject obj1, jobject obj2) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700786 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700787 return (Decode<Object*>(ts, obj1) == Decode<Object*>(ts, obj2))
788 ? JNI_TRUE : JNI_FALSE;
Carl Shapiroea4dca82011-08-01 13:45:38 -0700789}
790
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700791jint EnsureLocalCapacity(JNIEnv* env, jint) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700792 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700793 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700794 return 0;
795}
796
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700797jobject AllocObject(JNIEnv* env, jclass clazz) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700798 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700799 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700800 return NULL;
801}
802
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700803jobject NewObject(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700804 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700805 va_list args;
806 va_start(args, methodID);
807 jobject result = NewObjectV(env, clazz, methodID, args);
808 va_end(args);
809 return result;
Carl Shapiroea4dca82011-08-01 13:45:38 -0700810}
811
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700812jobject NewObjectV(JNIEnv* env,
813 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700814 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700815 Class* klass = Decode<Class*>(ts, clazz);
816 Object* result = klass->NewInstance();
817 jobject local_result = AddLocalReference<jobject>(ts, result);
818 CallNonvirtualVoidMethodV(env, local_result, clazz, methodID, args);
819 return local_result;
Carl Shapiroea4dca82011-08-01 13:45:38 -0700820}
821
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700822jobject NewObjectA(JNIEnv* env,
823 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700824 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700825 Class* klass = Decode<Class*>(ts, clazz);
826 Object* result = klass->NewInstance();
827 jobject local_result = AddLocalReference<jobjectArray>(ts, result);
828 CallNonvirtualVoidMethodA(env, local_result, clazz, methodID, args);
829 return local_result;
Carl Shapiroea4dca82011-08-01 13:45:38 -0700830}
831
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700832jclass GetObjectClass(JNIEnv* env, jobject obj) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700833 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700834 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700835 return NULL;
836}
837
Ian Rogers4dd71f12011-08-16 14:16:02 -0700838jboolean IsInstanceOf(JNIEnv* env, jobject jobj, jclass clazz) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700839 ScopedJniThreadState ts(env);
Ian Rogers4dd71f12011-08-16 14:16:02 -0700840 CHECK_NE(static_cast<jclass>(NULL), clazz);
841 if (jobj == NULL) {
842 // NB. JNI is different from regular Java instanceof in this respect
843 return JNI_TRUE;
844 } else {
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700845 Object* obj = Decode<Object*>(ts, jobj);
846 Class* klass = Decode<Class*>(ts, clazz);
Ian Rogers4dd71f12011-08-16 14:16:02 -0700847 return Object::InstanceOf(obj, klass) ? JNI_TRUE : JNI_FALSE;
848 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700849}
850
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700851jmethodID GetMethodID(JNIEnv* env,
852 jclass clazz, const char* name, const char* sig) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700853 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700854 Class* klass = Decode<Class*>(ts, clazz);
Carl Shapiro83ab4f32011-08-15 20:21:39 -0700855 if (!klass->IsInitialized()) {
856 // TODO: initialize the class
857 }
858 Method* method = klass->FindVirtualMethod(name, sig);
859 if (method == NULL) {
860 // No virtual method matching the signature. Search declared
861 // private methods and constructors.
862 method = klass->FindDeclaredDirectMethod(name, sig);
863 }
Ian Rogers4dd71f12011-08-16 14:16:02 -0700864 if (method == NULL) {
865 Thread* self = Thread::Current();
866 std::string class_name = klass->GetDescriptor().ToString();
867 // TODO: pretty print method names through a single routine
868 self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
869 "no method \"%s.%s%s\"",
870 class_name.c_str(), name, sig);
Carl Shapiro83ab4f32011-08-15 20:21:39 -0700871 return NULL;
Ian Rogers4dd71f12011-08-16 14:16:02 -0700872 } else if (method->IsStatic()) {
873 Thread* self = Thread::Current();
874 std::string class_name = klass->GetDescriptor().ToString();
875 // TODO: pretty print method names through a single routine
876 self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
877 "method \"%s.%s%s\" is static",
878 class_name.c_str(), name, sig);
Carl Shapiro83ab4f32011-08-15 20:21:39 -0700879 return NULL;
Ian Rogers4dd71f12011-08-16 14:16:02 -0700880 } else {
881 // TODO: create a JNI weak global reference for method
882 bool success = EnsureInvokeStub(method);
883 if (!success) {
884 // TODO: throw OutOfMemoryException
885 return NULL;
886 }
887 return reinterpret_cast<jmethodID>(method);
Carl Shapiro83ab4f32011-08-15 20:21:39 -0700888 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700889}
890
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700891jobject CallObjectMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700892 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700893 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700894 return NULL;
895}
896
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700897jobject CallObjectMethodV(JNIEnv* env,
898 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700899 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700900 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700901 return NULL;
902}
903
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700904jobject CallObjectMethodA(JNIEnv* env,
905 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700906 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700907 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700908 return NULL;
909}
910
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700911jboolean CallBooleanMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700912 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700913 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700914 return JNI_FALSE;
915}
916
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700917jboolean CallBooleanMethodV(JNIEnv* env,
918 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700919 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700920 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700921 return JNI_FALSE;
922}
923
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700924jboolean CallBooleanMethodA(JNIEnv* env,
925 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700926 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700927 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700928 return JNI_FALSE;
929}
930
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700931jbyte CallByteMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700932 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700933 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700934 return 0;
935}
936
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700937jbyte CallByteMethodV(JNIEnv* env,
938 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700939 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700940 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700941 return 0;
942}
943
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700944jbyte CallByteMethodA(JNIEnv* env,
945 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700946 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700947 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700948 return 0;
949}
950
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700951jchar CallCharMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700952 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700953 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700954 return 0;
955}
956
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700957jchar CallCharMethodV(JNIEnv* env,
958 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700959 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700960 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700961 return 0;
962}
963
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700964jchar CallCharMethodA(JNIEnv* env,
965 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700966 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700967 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700968 return 0;
969}
970
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700971jshort CallShortMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700972 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700973 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700974 return 0;
975}
976
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700977jshort CallShortMethodV(JNIEnv* env,
978 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700979 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700980 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700981 return 0;
982}
983
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700984jshort CallShortMethodA(JNIEnv* env,
985 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700986 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700987 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700988 return 0;
989}
990
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700991jint CallIntMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700992 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700993 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700994 return 0;
995}
996
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700997jint CallIntMethodV(JNIEnv* env,
998 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700999 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001000 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001001 return 0;
1002}
1003
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001004jint CallIntMethodA(JNIEnv* env,
1005 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001006 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001007 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001008 return 0;
1009}
1010
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001011jlong CallLongMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001012 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001013 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001014 return 0;
1015}
1016
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001017jlong CallLongMethodV(JNIEnv* env,
1018 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001019 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001020 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001021 return 0;
1022}
1023
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001024jlong CallLongMethodA(JNIEnv* env,
1025 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001026 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001027 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001028 return 0;
1029}
1030
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001031jfloat CallFloatMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001032 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001033 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001034 return 0;
1035}
1036
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001037jfloat CallFloatMethodV(JNIEnv* env,
1038 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001039 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001040 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001041 return 0;
1042}
1043
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001044jfloat CallFloatMethodA(JNIEnv* env,
1045 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001046 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001047 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001048 return 0;
1049}
1050
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001051jdouble CallDoubleMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001052 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001053 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001054 return 0;
1055}
1056
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001057jdouble CallDoubleMethodV(JNIEnv* env,
1058 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001059 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001060 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001061 return 0;
1062}
1063
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001064jdouble CallDoubleMethodA(JNIEnv* env,
1065 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001066 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001067 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001068 return 0;
1069}
1070
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001071void CallVoidMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001072 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001073 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001074}
1075
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001076void CallVoidMethodV(JNIEnv* env, jobject obj,
1077 jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001078 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001079 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001080}
1081
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001082void CallVoidMethodA(JNIEnv* env, jobject obj,
1083 jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001084 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001085 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001086}
1087
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001088jobject CallNonvirtualObjectMethod(JNIEnv* env,
1089 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001090 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001091 va_list ap;
1092 va_start(ap, methodID);
1093 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1094 jobject local_result = AddLocalReference<jobject>(ts, result.l);
1095 va_end(ap);
1096 return local_result;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001097}
1098
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001099jobject CallNonvirtualObjectMethodV(JNIEnv* env,
1100 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001101 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001102 JValue result = InvokeWithVarArgs(ts, obj, methodID, args);
1103 return AddLocalReference<jobject>(ts, result.l);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001104}
1105
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001106jobject CallNonvirtualObjectMethodA(JNIEnv* env,
1107 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001108 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001109 JValue result = InvokeWithJValues(ts, obj, methodID, args);
1110 return AddLocalReference<jobject>(ts, result.l);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001111}
1112
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001113jboolean CallNonvirtualBooleanMethod(JNIEnv* env,
1114 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001115 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001116 va_list ap;
1117 va_start(ap, methodID);
1118 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1119 va_end(ap);
1120 return result.z;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001121}
1122
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001123jboolean CallNonvirtualBooleanMethodV(JNIEnv* env,
1124 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001125 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001126 return InvokeWithVarArgs(ts, obj, methodID, args).z;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001127}
1128
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001129jboolean CallNonvirtualBooleanMethodA(JNIEnv* env,
1130 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001131 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001132 return InvokeWithJValues(ts, obj, methodID, args).z;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001133}
1134
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001135jbyte CallNonvirtualByteMethod(JNIEnv* env,
1136 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001137 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001138 va_list ap;
1139 va_start(ap, methodID);
1140 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1141 va_end(ap);
1142 return result.b;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001143}
1144
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001145jbyte CallNonvirtualByteMethodV(JNIEnv* env,
1146 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001147 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001148 return InvokeWithVarArgs(ts, obj, methodID, args).b;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001149}
1150
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001151jbyte CallNonvirtualByteMethodA(JNIEnv* env,
1152 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001153 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001154 return InvokeWithJValues(ts, obj, methodID, args).b;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001155}
1156
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001157jchar CallNonvirtualCharMethod(JNIEnv* env,
1158 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001159 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001160 va_list ap;
1161 va_start(ap, methodID);
1162 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1163 va_end(ap);
1164 return result.c;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001165}
1166
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001167jchar CallNonvirtualCharMethodV(JNIEnv* env,
1168 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001169 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001170 return InvokeWithVarArgs(ts, obj, methodID, args).c;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001171}
1172
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001173jchar CallNonvirtualCharMethodA(JNIEnv* env,
1174 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001175 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001176 return InvokeWithJValues(ts, obj, methodID, args).c;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001177}
1178
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001179jshort CallNonvirtualShortMethod(JNIEnv* env,
1180 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001181 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001182 va_list ap;
1183 va_start(ap, methodID);
1184 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1185 va_end(ap);
1186 return result.s;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001187}
1188
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001189jshort CallNonvirtualShortMethodV(JNIEnv* env,
1190 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001191 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001192 return InvokeWithVarArgs(ts, obj, methodID, args).s;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001193}
1194
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001195jshort CallNonvirtualShortMethodA(JNIEnv* env,
1196 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001197 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001198 return InvokeWithJValues(ts, obj, methodID, args).s;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001199}
1200
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001201jint CallNonvirtualIntMethod(JNIEnv* env,
1202 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001203 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001204 va_list ap;
1205 va_start(ap, methodID);
1206 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1207 va_end(ap);
1208 return result.i;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001209}
1210
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001211jint CallNonvirtualIntMethodV(JNIEnv* env,
1212 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001213 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001214 return InvokeWithVarArgs(ts, obj, methodID, args).i;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001215}
1216
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001217jint CallNonvirtualIntMethodA(JNIEnv* env,
1218 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001219 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001220 return InvokeWithJValues(ts, obj, methodID, args).i;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001221}
1222
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001223jlong CallNonvirtualLongMethod(JNIEnv* env,
1224 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001225 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001226 va_list ap;
1227 va_start(ap, methodID);
1228 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1229 va_end(ap);
1230 return result.j;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001231}
1232
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001233jlong CallNonvirtualLongMethodV(JNIEnv* env,
1234 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001235 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001236 return InvokeWithVarArgs(ts, obj, methodID, args).j;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001237}
1238
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001239jlong CallNonvirtualLongMethodA(JNIEnv* env,
1240 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001241 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001242 return InvokeWithJValues(ts, obj, methodID, args).j;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001243}
1244
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001245jfloat CallNonvirtualFloatMethod(JNIEnv* env,
1246 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001247 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001248 va_list ap;
1249 va_start(ap, methodID);
1250 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1251 va_end(ap);
1252 return result.f;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001253}
1254
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001255jfloat CallNonvirtualFloatMethodV(JNIEnv* env,
1256 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001257 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001258 return InvokeWithVarArgs(ts, obj, methodID, args).f;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001259}
1260
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001261jfloat CallNonvirtualFloatMethodA(JNIEnv* env,
1262 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001263 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001264 return InvokeWithJValues(ts, obj, methodID, args).f;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001265}
1266
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001267jdouble CallNonvirtualDoubleMethod(JNIEnv* env,
1268 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001269 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001270 va_list ap;
1271 va_start(ap, methodID);
1272 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1273 va_end(ap);
1274 return result.d;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001275}
1276
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001277jdouble CallNonvirtualDoubleMethodV(JNIEnv* env,
1278 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001279 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001280 return InvokeWithVarArgs(ts, obj, methodID, args).d;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001281}
1282
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001283jdouble CallNonvirtualDoubleMethodA(JNIEnv* env,
1284 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001285 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001286 return InvokeWithJValues(ts, obj, methodID, args).d;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001287}
1288
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001289void CallNonvirtualVoidMethod(JNIEnv* env,
1290 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001291 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001292 va_list ap;
1293 va_start(ap, methodID);
1294 InvokeWithVarArgs(ts, obj, methodID, ap);
1295 va_end(ap);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001296}
1297
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001298void CallNonvirtualVoidMethodV(JNIEnv* env,
1299 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001300 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001301 InvokeWithVarArgs(ts, obj, methodID, args);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001302}
1303
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001304void CallNonvirtualVoidMethodA(JNIEnv* env,
1305 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001306 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001307 InvokeWithJValues(ts, obj, methodID, args);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001308}
1309
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001310jfieldID GetFieldID(JNIEnv* env,
1311 jclass clazz, const char* name, const char* sig) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001312 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001313 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001314 return NULL;
1315}
1316
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001317jobject GetObjectField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001318 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001319 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001320 return NULL;
1321}
1322
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001323jboolean GetBooleanField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001324 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001325 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001326 return JNI_FALSE;
1327}
1328
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001329jbyte GetByteField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001330 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001331 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001332 return 0;
1333}
1334
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001335jchar GetCharField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001336 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001337 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001338 return 0;
1339}
1340
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001341jshort GetShortField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001342 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001343 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001344 return 0;
1345}
1346
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001347jint GetIntField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001348 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001349 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001350 return 0;
1351}
1352
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001353jlong GetLongField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001354 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001355 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001356 return 0;
1357}
1358
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001359jfloat GetFloatField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001360 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001361 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001362 return 0;
1363}
1364
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001365jdouble GetDoubleField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001366 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001367 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001368 return 0;
1369}
1370
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001371void SetObjectField(JNIEnv* env, jobject obj, jfieldID fieldID, jobject val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001372 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001373 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001374}
1375
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001376void SetBooleanField(JNIEnv* env, jobject obj, jfieldID fieldID, jboolean val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001377 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001378 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001379}
1380
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001381void SetByteField(JNIEnv* env, jobject obj, jfieldID fieldID, jbyte val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001382 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001383 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001384}
1385
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001386void SetCharField(JNIEnv* env, jobject obj, jfieldID fieldID, jchar val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001387 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001388 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001389}
1390
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001391void SetShortField(JNIEnv* env, jobject obj, jfieldID fieldID, jshort val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001392 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001393 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001394}
1395
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001396void SetIntField(JNIEnv* env, jobject obj, jfieldID fieldID, jint val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001397 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001398 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001399}
1400
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001401void SetLongField(JNIEnv* env, jobject obj, jfieldID fieldID, jlong val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001402 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001403 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001404}
1405
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001406void SetFloatField(JNIEnv* env, jobject obj, jfieldID fieldID, jfloat val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001407 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001408 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001409}
1410
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001411void SetDoubleField(JNIEnv* env, jobject obj, jfieldID fieldID, jdouble val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001412 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001413 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001414}
1415
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001416jmethodID GetStaticMethodID(JNIEnv* env,
1417 jclass clazz, const char* name, const char* sig) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001418 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001419 Class* klass = Decode<Class*>(ts, clazz);
Carl Shapiro83ab4f32011-08-15 20:21:39 -07001420 if (!klass->IsInitialized()) {
1421 // TODO: initialize the class
1422 }
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001423 Method* method = klass->FindDirectMethod(name, sig);
Ian Rogers4dd71f12011-08-16 14:16:02 -07001424 if (method == NULL) {
1425 Thread* self = Thread::Current();
1426 std::string class_name = klass->GetDescriptor().ToString();
1427 // TODO: pretty print method names through a single routine
1428 // TODO: may want to FindVirtualMethod to give more informative error
1429 // message here
1430 self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
1431 "no method \"%s.%s%s\"",
1432 class_name.c_str(), name, sig);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001433 return NULL;
Ian Rogers4dd71f12011-08-16 14:16:02 -07001434 } else if (!method->IsStatic()) {
1435 Thread* self = Thread::Current();
1436 std::string class_name = klass->GetDescriptor().ToString();
1437 // TODO: pretty print method names through a single routine
1438 self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
1439 "method \"%s.%s%s\" is not static",
1440 class_name.c_str(), name, sig);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001441 return NULL;
Ian Rogers4dd71f12011-08-16 14:16:02 -07001442 } else {
1443 // TODO: create a JNI weak global reference for method
1444 bool success = EnsureInvokeStub(method);
1445 if (!success) {
1446 // TODO: throw OutOfMemoryException
1447 return NULL;
1448 }
1449 return reinterpret_cast<jmethodID>(method);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001450 }
Carl Shapiroea4dca82011-08-01 13:45:38 -07001451}
1452
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001453jobject CallStaticObjectMethod(JNIEnv* env,
1454 jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001455 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001456 va_list ap;
1457 va_start(ap, methodID);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001458 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001459 jobject local_result = AddLocalReference<jobject>(ts, result.l);
1460 va_end(ap);
1461 return local_result;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001462}
1463
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001464jobject CallStaticObjectMethodV(JNIEnv* env,
1465 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001466 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001467 JValue result = InvokeWithVarArgs(ts, NULL, methodID, args);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001468 return AddLocalReference<jobject>(ts, result.l);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001469}
1470
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001471jobject CallStaticObjectMethodA(JNIEnv* env,
1472 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001473 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001474 JValue result = InvokeWithJValues(ts, NULL, methodID, args);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001475 return AddLocalReference<jobject>(ts, result.l);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001476}
1477
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001478jboolean CallStaticBooleanMethod(JNIEnv* env,
1479 jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001480 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001481 va_list ap;
1482 va_start(ap, methodID);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001483 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1484 va_end(ap);
1485 return result.z;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001486}
1487
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001488jboolean CallStaticBooleanMethodV(JNIEnv* env,
1489 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001490 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001491 return InvokeWithVarArgs(ts, NULL, methodID, args).z;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001492}
1493
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001494jboolean CallStaticBooleanMethodA(JNIEnv* env,
1495 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001496 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001497 return InvokeWithJValues(ts, NULL, methodID, args).z;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001498}
1499
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001500jbyte CallStaticByteMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001501 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001502 va_list ap;
1503 va_start(ap, methodID);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001504 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1505 va_end(ap);
1506 return result.b;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001507}
1508
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001509jbyte CallStaticByteMethodV(JNIEnv* env,
1510 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001511 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001512 return InvokeWithVarArgs(ts, NULL, methodID, args).b;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001513}
1514
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001515jbyte CallStaticByteMethodA(JNIEnv* env,
1516 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001517 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001518 return InvokeWithJValues(ts, NULL, methodID, args).b;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001519}
1520
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001521jchar CallStaticCharMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001522 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001523 va_list ap;
1524 va_start(ap, methodID);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001525 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1526 va_end(ap);
1527 return result.c;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001528}
1529
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001530jchar CallStaticCharMethodV(JNIEnv* env,
1531 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001532 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001533 return InvokeWithVarArgs(ts, NULL, methodID, args).c;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001534}
1535
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001536jchar CallStaticCharMethodA(JNIEnv* env,
1537 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001538 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001539 return InvokeWithJValues(ts, NULL, methodID, args).c;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001540}
1541
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001542jshort CallStaticShortMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001543 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001544 va_list ap;
1545 va_start(ap, methodID);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001546 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1547 va_end(ap);
1548 return result.s;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001549}
1550
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001551jshort CallStaticShortMethodV(JNIEnv* env,
1552 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001553 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001554 return InvokeWithVarArgs(ts, NULL, methodID, args).s;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001555}
1556
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001557jshort CallStaticShortMethodA(JNIEnv* env,
1558 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001559 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001560 return InvokeWithJValues(ts, NULL, methodID, args).s;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001561}
1562
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001563jint CallStaticIntMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001564 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001565 va_list ap;
1566 va_start(ap, methodID);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001567 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1568 va_end(ap);
1569 return result.i;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001570}
1571
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001572jint CallStaticIntMethodV(JNIEnv* env,
1573 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001574 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001575 return InvokeWithVarArgs(ts, NULL, methodID, args).i;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001576}
1577
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001578jint CallStaticIntMethodA(JNIEnv* env,
1579 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001580 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001581 return InvokeWithJValues(ts, NULL, methodID, args).i;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001582}
1583
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001584jlong CallStaticLongMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001585 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001586 va_list ap;
1587 va_start(ap, methodID);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001588 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1589 va_end(ap);
1590 return result.j;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001591}
1592
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001593jlong CallStaticLongMethodV(JNIEnv* env,
1594 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001595 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001596 return InvokeWithVarArgs(ts, NULL, methodID, args).j;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001597}
1598
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001599jlong CallStaticLongMethodA(JNIEnv* env,
1600 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001601 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001602 return InvokeWithJValues(ts, NULL, methodID, args).j;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001603}
1604
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001605jfloat CallStaticFloatMethod(JNIEnv* env, jclass cls, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001606 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001607 va_list ap;
1608 va_start(ap, methodID);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001609 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1610 va_end(ap);
1611 return result.f;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001612}
1613
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001614jfloat CallStaticFloatMethodV(JNIEnv* env,
1615 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001616 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001617 return InvokeWithVarArgs(ts, NULL, methodID, args).f;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001618}
1619
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001620jfloat CallStaticFloatMethodA(JNIEnv* env,
1621 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001622 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001623 return InvokeWithJValues(ts, NULL, methodID, args).f;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001624}
1625
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001626jdouble CallStaticDoubleMethod(JNIEnv* env, jclass cls, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001627 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001628 va_list ap;
1629 va_start(ap, methodID);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001630 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1631 va_end(ap);
1632 return result.d;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001633}
1634
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001635jdouble CallStaticDoubleMethodV(JNIEnv* env,
1636 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001637 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001638 return InvokeWithVarArgs(ts, NULL, methodID, args).d;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001639}
1640
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001641jdouble CallStaticDoubleMethodA(JNIEnv* env,
1642 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001643 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001644 return InvokeWithJValues(ts, NULL, methodID, args).d;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001645}
1646
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001647void CallStaticVoidMethod(JNIEnv* env, jclass cls, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001648 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001649 va_list ap;
1650 va_start(ap, methodID);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001651 InvokeWithVarArgs(ts, NULL, methodID, ap);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001652 va_end(ap);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001653}
1654
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001655void CallStaticVoidMethodV(JNIEnv* env,
1656 jclass cls, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001657 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001658 InvokeWithVarArgs(ts, NULL, methodID, args);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001659}
1660
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001661void CallStaticVoidMethodA(JNIEnv* env,
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001662 jclass cls, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001663 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001664 InvokeWithJValues(ts, NULL, methodID, args);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001665}
1666
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001667jfieldID GetStaticFieldID(JNIEnv* env,
1668 jclass clazz, const char* name, const char* sig) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001669 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001670 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001671 return 0;
1672}
1673
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001674jobject GetStaticObjectField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001675 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001676 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001677 return NULL;
1678}
1679
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001680jboolean GetStaticBooleanField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001681 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001682 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001683 return JNI_FALSE;
1684}
1685
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001686jbyte GetStaticByteField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001687 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001688 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001689 return 0;
1690}
1691
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001692jchar GetStaticCharField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001693 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001694 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001695 return 0;
1696}
1697
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001698jshort GetStaticShortField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001699 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001700 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001701 return 0;
1702}
1703
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001704jint GetStaticIntField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001705 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001706 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001707 return 0;
1708}
1709
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001710jlong GetStaticLongField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001711 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001712 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001713 return 0;
1714}
1715
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001716jfloat GetStaticFloatField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001717 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001718 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001719 return 0;
1720}
1721
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001722jdouble GetStaticDoubleField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001723 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001724 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001725 return 0;
1726}
1727
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001728void SetStaticObjectField(JNIEnv* env,
1729 jclass clazz, jfieldID fieldID, jobject value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001730 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001731 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001732}
1733
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001734void SetStaticBooleanField(JNIEnv* env,
1735 jclass clazz, jfieldID fieldID, jboolean value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001736 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001737 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001738}
1739
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001740void SetStaticByteField(JNIEnv* env,
1741 jclass clazz, jfieldID fieldID, jbyte value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001742 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001743 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001744}
1745
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001746void SetStaticCharField(JNIEnv* env,
1747 jclass clazz, jfieldID fieldID, jchar value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001748 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001749 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001750}
1751
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001752void SetStaticShortField(JNIEnv* env,
1753 jclass clazz, jfieldID fieldID, jshort value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001754 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001755 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001756}
1757
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001758void SetStaticIntField(JNIEnv* env,
1759 jclass clazz, jfieldID fieldID, jint value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001760 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001761 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001762}
1763
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001764void SetStaticLongField(JNIEnv* env,
1765 jclass clazz, jfieldID fieldID, jlong value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001766 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001767 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001768}
1769
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001770void SetStaticFloatField(JNIEnv* env,
1771 jclass clazz, jfieldID fieldID, jfloat value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001772 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001773 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001774}
1775
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001776void SetStaticDoubleField(JNIEnv* env,
1777 jclass clazz, jfieldID fieldID, jdouble value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001778 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001779 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001780}
1781
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001782jstring NewString(JNIEnv* env, const jchar* unicode, jsize len) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001783 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001784 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001785 return NULL;
1786}
1787
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001788jsize GetStringLength(JNIEnv* env, jstring str) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001789 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001790 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001791 return 0;
1792}
1793
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001794const jchar* GetStringChars(JNIEnv* env, jstring str, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001795 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001796 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001797 return NULL;
1798}
1799
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001800void ReleaseStringChars(JNIEnv* env, jstring str, const jchar* chars) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001801 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001802 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001803}
1804
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001805jstring NewStringUTF(JNIEnv* env, const char* utf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001806 ScopedJniThreadState ts(env);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001807 if (utf == NULL) {
1808 return NULL;
1809 }
Elliott Hughesbfaadc82011-08-18 17:36:58 -07001810 String* result = String::AllocFromModifiedUtf8(utf);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001811 return AddLocalReference<jstring>(ts, result);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001812}
1813
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001814jsize GetStringUTFLength(JNIEnv* env, jstring str) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001815 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001816 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001817 return 0;
1818}
1819
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001820const char* GetStringUTFChars(JNIEnv* env, jstring str, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001821 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001822 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001823 return NULL;
1824}
1825
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001826void ReleaseStringUTFChars(JNIEnv* env, jstring str, const char* chars) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001827 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001828 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001829}
1830
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001831jsize GetArrayLength(JNIEnv* env, jarray array) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001832 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001833 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001834 return 0;
1835}
1836
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001837jobject GetObjectArrayElement(JNIEnv* env, jobjectArray array, jsize index) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001838 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001839 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001840 return NULL;
1841}
1842
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001843void SetObjectArrayElement(JNIEnv* env,
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001844 jobjectArray java_array, jsize index, jobject java_value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001845 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001846 ObjectArray<Object>* array = Decode<ObjectArray<Object>*>(ts, java_array);
1847 Object* value = Decode<Object*>(ts, java_value);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001848 array->Set(index, value);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001849}
1850
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001851template<typename JniT, typename ArtT>
1852JniT NewPrimitiveArray(ScopedJniThreadState& ts, jsize length) {
1853 CHECK_GE(length, 0); // TODO: ReportJniError
1854 ArtT* result = ArtT::Alloc(length);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001855 return AddLocalReference<JniT>(ts, result);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001856}
1857
Elliott Hughesf2682d52011-08-15 16:37:04 -07001858jbooleanArray NewBooleanArray(JNIEnv* env, jsize length) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001859 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001860 return NewPrimitiveArray<jbooleanArray, BooleanArray>(ts, length);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001861}
1862
Elliott Hughesf2682d52011-08-15 16:37:04 -07001863jbyteArray NewByteArray(JNIEnv* env, jsize length) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001864 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001865 return NewPrimitiveArray<jbyteArray, ByteArray>(ts, length);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001866}
1867
Elliott Hughesf2682d52011-08-15 16:37:04 -07001868jcharArray NewCharArray(JNIEnv* env, jsize length) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001869 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001870 return NewPrimitiveArray<jcharArray, CharArray>(ts, length);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001871}
1872
Elliott Hughesf2682d52011-08-15 16:37:04 -07001873jdoubleArray NewDoubleArray(JNIEnv* env, jsize length) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001874 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001875 return NewPrimitiveArray<jdoubleArray, DoubleArray>(ts, length);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001876}
1877
Elliott Hughesf2682d52011-08-15 16:37:04 -07001878jfloatArray NewFloatArray(JNIEnv* env, jsize length) {
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001879 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001880 return NewPrimitiveArray<jfloatArray, FloatArray>(ts, length);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001881}
1882
Elliott Hughesf2682d52011-08-15 16:37:04 -07001883jintArray NewIntArray(JNIEnv* env, jsize length) {
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001884 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001885 return NewPrimitiveArray<jintArray, IntArray>(ts, length);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001886}
1887
Elliott Hughesf2682d52011-08-15 16:37:04 -07001888jlongArray NewLongArray(JNIEnv* env, jsize length) {
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001889 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001890 return NewPrimitiveArray<jlongArray, LongArray>(ts, length);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001891}
1892
Elliott Hughesf2682d52011-08-15 16:37:04 -07001893jobjectArray NewObjectArray(JNIEnv* env, jsize length, jclass element_jclass, jobject initial_element) {
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001894 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001895 CHECK_GE(length, 0); // TODO: ReportJniError
1896
1897 // Compute the array class corresponding to the given element class.
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001898 Class* element_class = Decode<Class*>(ts, element_jclass);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001899 std::string descriptor;
1900 descriptor += "[";
1901 descriptor += element_class->GetDescriptor().ToString();
1902
1903 // Find the class.
1904 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
1905 // TODO: need to get the appropriate ClassLoader.
1906 Class* array_class = class_linker->FindClass(descriptor, NULL);
1907 if (array_class == NULL) {
1908 return NULL;
1909 }
1910
1911 ObjectArray<Object>* result = ObjectArray<Object>::Alloc(array_class, length);
1912 CHECK(initial_element == NULL); // TODO: support initial_element
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001913 return AddLocalReference<jobjectArray>(ts, result);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001914}
1915
1916jshortArray NewShortArray(JNIEnv* env, jsize length) {
1917 ScopedJniThreadState ts(env);
1918 return NewPrimitiveArray<jshortArray, ShortArray>(ts, length);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001919}
1920
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001921jboolean* GetBooleanArrayElements(JNIEnv* env,
1922 jbooleanArray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001923 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001924 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001925 return NULL;
1926}
1927
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001928jbyte* GetByteArrayElements(JNIEnv* env, jbyteArray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001929 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001930 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001931 return NULL;
1932}
1933
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001934jchar* GetCharArrayElements(JNIEnv* env, jcharArray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001935 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001936 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001937 return NULL;
1938}
1939
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001940jshort* GetShortArrayElements(JNIEnv* env,
1941 jshortArray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001942 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001943 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001944 return NULL;
1945}
1946
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001947jint* GetIntArrayElements(JNIEnv* env, jintArray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001948 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001949 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001950 return NULL;
1951}
1952
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001953jlong* GetLongArrayElements(JNIEnv* env, jlongArray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001954 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001955 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001956 return NULL;
1957}
1958
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001959jfloat* GetFloatArrayElements(JNIEnv* env,
1960 jfloatArray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001961 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001962 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001963 return NULL;
1964}
1965
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001966jdouble* GetDoubleArrayElements(JNIEnv* env,
1967 jdoubleArray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001968 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001969 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001970 return NULL;
1971}
1972
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001973void ReleaseBooleanArrayElements(JNIEnv* env,
1974 jbooleanArray array, jboolean* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001975 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001976 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001977}
1978
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001979void ReleaseByteArrayElements(JNIEnv* env,
1980 jbyteArray array, jbyte* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001981 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001982 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001983}
1984
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001985void ReleaseCharArrayElements(JNIEnv* env,
1986 jcharArray array, jchar* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001987 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001988 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001989}
1990
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001991void ReleaseShortArrayElements(JNIEnv* env,
1992 jshortArray array, jshort* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001993 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001994 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001995}
1996
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001997void ReleaseIntArrayElements(JNIEnv* env,
1998 jintArray array, jint* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001999 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002000 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002001}
2002
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002003void ReleaseLongArrayElements(JNIEnv* env,
2004 jlongArray array, jlong* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002005 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002006 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002007}
2008
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002009void ReleaseFloatArrayElements(JNIEnv* env,
2010 jfloatArray array, jfloat* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002011 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002012 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002013}
2014
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002015void ReleaseDoubleArrayElements(JNIEnv* env,
2016 jdoubleArray array, jdouble* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002017 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002018 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002019}
2020
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002021void GetBooleanArrayRegion(JNIEnv* env,
2022 jbooleanArray array, jsize start, jsize l, jboolean* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002023 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002024 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002025}
2026
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002027void GetByteArrayRegion(JNIEnv* env,
2028 jbyteArray array, jsize start, jsize len, jbyte* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002029 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002030 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002031}
2032
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002033void GetCharArrayRegion(JNIEnv* env,
2034 jcharArray array, jsize start, jsize len, jchar* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002035 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002036 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002037}
2038
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002039void GetShortArrayRegion(JNIEnv* env,
2040 jshortArray array, jsize start, jsize len, jshort* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002041 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002042 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002043}
2044
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002045void GetIntArrayRegion(JNIEnv* env,
2046 jintArray array, jsize start, jsize len, jint* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002047 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002048 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002049}
2050
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002051void GetLongArrayRegion(JNIEnv* env,
2052 jlongArray array, jsize start, jsize len, jlong* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002053 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002054 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002055}
2056
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002057void GetFloatArrayRegion(JNIEnv* env,
2058 jfloatArray array, jsize start, jsize len, jfloat* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002059 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002060 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002061}
2062
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002063void GetDoubleArrayRegion(JNIEnv* env,
2064 jdoubleArray array, jsize start, jsize len, jdouble* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002065 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002066 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002067}
2068
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002069void SetBooleanArrayRegion(JNIEnv* env,
2070 jbooleanArray array, jsize start, jsize l, const jboolean* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002071 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002072 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002073}
2074
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002075void SetByteArrayRegion(JNIEnv* env,
2076 jbyteArray array, jsize start, jsize len, const jbyte* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002077 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002078 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002079}
2080
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002081void SetCharArrayRegion(JNIEnv* env,
2082 jcharArray array, jsize start, jsize len, const jchar* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002083 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002084 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002085}
2086
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002087void SetShortArrayRegion(JNIEnv* env,
2088 jshortArray array, jsize start, jsize len, const jshort* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002089 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002090 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002091}
2092
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002093void SetIntArrayRegion(JNIEnv* env,
2094 jintArray array, jsize start, jsize len, const jint* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002095 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002096 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002097}
2098
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002099void SetLongArrayRegion(JNIEnv* env,
2100 jlongArray array, jsize start, jsize len, const jlong* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002101 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002102 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002103}
2104
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002105void SetFloatArrayRegion(JNIEnv* env,
2106 jfloatArray array, jsize start, jsize len, const jfloat* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002107 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002108 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002109}
2110
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002111void SetDoubleArrayRegion(JNIEnv* env,
2112 jdoubleArray array, jsize start, jsize len, const jdouble* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002113 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002114 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002115}
2116
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002117jint RegisterNatives(JNIEnv* env,
2118 jclass clazz, const JNINativeMethod* methods, jint nMethods) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002119 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07002120 Class* klass = Decode<Class*>(ts, clazz);
Ian Rogers4dd71f12011-08-16 14:16:02 -07002121 for(int i = 0; i < nMethods; i++) {
2122 const char* name = methods[i].name;
2123 const char* sig = methods[i].signature;
Elliott Hughes0af55432011-08-17 18:37:28 -07002124
2125 if (*sig == '!') {
2126 // TODO: fast jni. it's too noisy to log all these.
2127 ++sig;
2128 }
2129
Ian Rogers4dd71f12011-08-16 14:16:02 -07002130 Method* method = klass->FindDirectMethod(name, sig);
2131 if (method == NULL) {
2132 method = klass->FindVirtualMethod(name, sig);
2133 }
2134 if (method == NULL) {
2135 Thread* self = Thread::Current();
2136 std::string class_name = klass->GetDescriptor().ToString();
2137 // TODO: pretty print method names through a single routine
2138 self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
2139 "no method \"%s.%s%s\"",
2140 class_name.c_str(), name, sig);
2141 return JNI_ERR;
2142 } else if (!method->IsNative()) {
2143 Thread* self = Thread::Current();
2144 std::string class_name = klass->GetDescriptor().ToString();
2145 // TODO: pretty print method names through a single routine
2146 self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
2147 "method \"%s.%s%s\" is not native",
2148 class_name.c_str(), name, sig);
2149 return JNI_ERR;
2150 }
2151 method->RegisterNative(methods[i].fnPtr);
2152 }
2153 return JNI_OK;
Carl Shapiroea4dca82011-08-01 13:45:38 -07002154}
2155
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002156jint UnregisterNatives(JNIEnv* env, jclass clazz) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002157 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002158 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002159 return 0;
2160}
2161
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002162jint MonitorEnter(JNIEnv* env, jobject obj) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002163 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002164 UNIMPLEMENTED(WARNING);
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002165 return 0;
2166}
2167
2168jint MonitorExit(JNIEnv* env, jobject obj) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002169 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002170 UNIMPLEMENTED(WARNING);
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002171 return 0;
2172}
2173
Elliott Hughesb20a5542011-08-12 18:03:12 -07002174jint GetJavaVM(JNIEnv* env, JavaVM** vm) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002175 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07002176 Runtime* runtime = Runtime::Current();
2177 if (runtime != NULL) {
Elliott Hughes0af55432011-08-17 18:37:28 -07002178 *vm = reinterpret_cast<JavaVM*>(runtime->GetJavaVM());
Elliott Hughesf2682d52011-08-15 16:37:04 -07002179 } else {
2180 *vm = NULL;
2181 }
2182 return (*vm != NULL) ? JNI_OK : JNI_ERR;
Carl Shapiroea4dca82011-08-01 13:45:38 -07002183}
2184
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002185void GetStringRegion(JNIEnv* env,
2186 jstring str, jsize start, jsize len, jchar* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002187 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002188 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002189}
2190
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002191void GetStringUTFRegion(JNIEnv* env,
2192 jstring str, jsize start, jsize len, char* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002193 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002194 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002195}
2196
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002197void* GetPrimitiveArrayCritical(JNIEnv* env,
2198 jarray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002199 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002200 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002201 return NULL;
2202}
2203
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002204void ReleasePrimitiveArrayCritical(JNIEnv* env,
2205 jarray array, void* carray, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002206 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002207 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002208}
2209
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002210const jchar* GetStringCritical(JNIEnv* env, jstring s, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002211 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002212 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002213 return NULL;
2214}
2215
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002216void ReleaseStringCritical(JNIEnv* env, jstring s, const jchar* cstr) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002217 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002218 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002219}
2220
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002221jboolean ExceptionCheck(JNIEnv* env) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002222 ScopedJniThreadState ts(env);
Elliott Hughesb20a5542011-08-12 18:03:12 -07002223 return ts.Self()->IsExceptionPending() ? JNI_TRUE : JNI_FALSE;
Carl Shapiroea4dca82011-08-01 13:45:38 -07002224}
2225
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002226jobject NewDirectByteBuffer(JNIEnv* env, void* address, jlong capacity) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002227 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002228 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002229 return NULL;
2230}
2231
2232
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002233void* GetDirectBufferAddress(JNIEnv* env, jobject buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002234 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002235 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002236 return NULL;
2237}
2238
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002239jlong GetDirectBufferCapacity(JNIEnv* env, jobject buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002240 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002241 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002242 return 0;
2243}
2244
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002245jobjectRefType GetObjectRefType(JNIEnv* env, jobject jobj) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002246 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002247 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002248 return JNIInvalidRefType;
2249}
2250
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002251static const struct JNINativeInterface gNativeInterface = {
Carl Shapiroea4dca82011-08-01 13:45:38 -07002252 NULL, // reserved0.
2253 NULL, // reserved1.
2254 NULL, // reserved2.
2255 NULL, // reserved3.
2256 GetVersion,
2257 DefineClass,
2258 FindClass,
2259 FromReflectedMethod,
2260 FromReflectedField,
2261 ToReflectedMethod,
2262 GetSuperclass,
2263 IsAssignableFrom,
2264 ToReflectedField,
2265 Throw,
2266 ThrowNew,
2267 ExceptionOccurred,
2268 ExceptionDescribe,
2269 ExceptionClear,
2270 FatalError,
2271 PushLocalFrame,
2272 PopLocalFrame,
2273 NewGlobalRef,
2274 DeleteGlobalRef,
2275 DeleteLocalRef,
2276 IsSameObject,
2277 NewLocalRef,
2278 EnsureLocalCapacity,
2279 AllocObject,
2280 NewObject,
2281 NewObjectV,
2282 NewObjectA,
2283 GetObjectClass,
2284 IsInstanceOf,
2285 GetMethodID,
2286 CallObjectMethod,
2287 CallObjectMethodV,
2288 CallObjectMethodA,
2289 CallBooleanMethod,
2290 CallBooleanMethodV,
2291 CallBooleanMethodA,
2292 CallByteMethod,
2293 CallByteMethodV,
2294 CallByteMethodA,
2295 CallCharMethod,
2296 CallCharMethodV,
2297 CallCharMethodA,
2298 CallShortMethod,
2299 CallShortMethodV,
2300 CallShortMethodA,
2301 CallIntMethod,
2302 CallIntMethodV,
2303 CallIntMethodA,
2304 CallLongMethod,
2305 CallLongMethodV,
2306 CallLongMethodA,
2307 CallFloatMethod,
2308 CallFloatMethodV,
2309 CallFloatMethodA,
2310 CallDoubleMethod,
2311 CallDoubleMethodV,
2312 CallDoubleMethodA,
2313 CallVoidMethod,
2314 CallVoidMethodV,
2315 CallVoidMethodA,
2316 CallNonvirtualObjectMethod,
2317 CallNonvirtualObjectMethodV,
2318 CallNonvirtualObjectMethodA,
2319 CallNonvirtualBooleanMethod,
2320 CallNonvirtualBooleanMethodV,
2321 CallNonvirtualBooleanMethodA,
2322 CallNonvirtualByteMethod,
2323 CallNonvirtualByteMethodV,
2324 CallNonvirtualByteMethodA,
2325 CallNonvirtualCharMethod,
2326 CallNonvirtualCharMethodV,
2327 CallNonvirtualCharMethodA,
2328 CallNonvirtualShortMethod,
2329 CallNonvirtualShortMethodV,
2330 CallNonvirtualShortMethodA,
2331 CallNonvirtualIntMethod,
2332 CallNonvirtualIntMethodV,
2333 CallNonvirtualIntMethodA,
2334 CallNonvirtualLongMethod,
2335 CallNonvirtualLongMethodV,
2336 CallNonvirtualLongMethodA,
2337 CallNonvirtualFloatMethod,
2338 CallNonvirtualFloatMethodV,
2339 CallNonvirtualFloatMethodA,
2340 CallNonvirtualDoubleMethod,
2341 CallNonvirtualDoubleMethodV,
2342 CallNonvirtualDoubleMethodA,
2343 CallNonvirtualVoidMethod,
2344 CallNonvirtualVoidMethodV,
2345 CallNonvirtualVoidMethodA,
2346 GetFieldID,
2347 GetObjectField,
2348 GetBooleanField,
2349 GetByteField,
2350 GetCharField,
2351 GetShortField,
2352 GetIntField,
2353 GetLongField,
2354 GetFloatField,
2355 GetDoubleField,
2356 SetObjectField,
2357 SetBooleanField,
2358 SetByteField,
2359 SetCharField,
2360 SetShortField,
2361 SetIntField,
2362 SetLongField,
2363 SetFloatField,
2364 SetDoubleField,
2365 GetStaticMethodID,
2366 CallStaticObjectMethod,
2367 CallStaticObjectMethodV,
2368 CallStaticObjectMethodA,
2369 CallStaticBooleanMethod,
2370 CallStaticBooleanMethodV,
2371 CallStaticBooleanMethodA,
2372 CallStaticByteMethod,
2373 CallStaticByteMethodV,
2374 CallStaticByteMethodA,
2375 CallStaticCharMethod,
2376 CallStaticCharMethodV,
2377 CallStaticCharMethodA,
2378 CallStaticShortMethod,
2379 CallStaticShortMethodV,
2380 CallStaticShortMethodA,
2381 CallStaticIntMethod,
2382 CallStaticIntMethodV,
2383 CallStaticIntMethodA,
2384 CallStaticLongMethod,
2385 CallStaticLongMethodV,
2386 CallStaticLongMethodA,
2387 CallStaticFloatMethod,
2388 CallStaticFloatMethodV,
2389 CallStaticFloatMethodA,
2390 CallStaticDoubleMethod,
2391 CallStaticDoubleMethodV,
2392 CallStaticDoubleMethodA,
2393 CallStaticVoidMethod,
2394 CallStaticVoidMethodV,
2395 CallStaticVoidMethodA,
2396 GetStaticFieldID,
2397 GetStaticObjectField,
2398 GetStaticBooleanField,
2399 GetStaticByteField,
2400 GetStaticCharField,
2401 GetStaticShortField,
2402 GetStaticIntField,
2403 GetStaticLongField,
2404 GetStaticFloatField,
2405 GetStaticDoubleField,
2406 SetStaticObjectField,
2407 SetStaticBooleanField,
2408 SetStaticByteField,
2409 SetStaticCharField,
2410 SetStaticShortField,
2411 SetStaticIntField,
2412 SetStaticLongField,
2413 SetStaticFloatField,
2414 SetStaticDoubleField,
2415 NewString,
2416 GetStringLength,
2417 GetStringChars,
2418 ReleaseStringChars,
2419 NewStringUTF,
2420 GetStringUTFLength,
2421 GetStringUTFChars,
2422 ReleaseStringUTFChars,
2423 GetArrayLength,
2424 NewObjectArray,
2425 GetObjectArrayElement,
2426 SetObjectArrayElement,
2427 NewBooleanArray,
2428 NewByteArray,
2429 NewCharArray,
2430 NewShortArray,
2431 NewIntArray,
2432 NewLongArray,
2433 NewFloatArray,
2434 NewDoubleArray,
2435 GetBooleanArrayElements,
2436 GetByteArrayElements,
2437 GetCharArrayElements,
2438 GetShortArrayElements,
2439 GetIntArrayElements,
2440 GetLongArrayElements,
2441 GetFloatArrayElements,
2442 GetDoubleArrayElements,
2443 ReleaseBooleanArrayElements,
2444 ReleaseByteArrayElements,
2445 ReleaseCharArrayElements,
2446 ReleaseShortArrayElements,
2447 ReleaseIntArrayElements,
2448 ReleaseLongArrayElements,
2449 ReleaseFloatArrayElements,
2450 ReleaseDoubleArrayElements,
2451 GetBooleanArrayRegion,
2452 GetByteArrayRegion,
2453 GetCharArrayRegion,
2454 GetShortArrayRegion,
2455 GetIntArrayRegion,
2456 GetLongArrayRegion,
2457 GetFloatArrayRegion,
2458 GetDoubleArrayRegion,
2459 SetBooleanArrayRegion,
2460 SetByteArrayRegion,
2461 SetCharArrayRegion,
2462 SetShortArrayRegion,
2463 SetIntArrayRegion,
2464 SetLongArrayRegion,
2465 SetFloatArrayRegion,
2466 SetDoubleArrayRegion,
2467 RegisterNatives,
2468 UnregisterNatives,
2469 MonitorEnter,
2470 MonitorExit,
2471 GetJavaVM,
2472 GetStringRegion,
2473 GetStringUTFRegion,
2474 GetPrimitiveArrayCritical,
2475 ReleasePrimitiveArrayCritical,
2476 GetStringCritical,
2477 ReleaseStringCritical,
2478 NewWeakGlobalRef,
2479 DeleteWeakGlobalRef,
2480 ExceptionCheck,
2481 NewDirectByteBuffer,
2482 GetDirectBufferAddress,
2483 GetDirectBufferCapacity,
2484 GetObjectRefType,
2485};
2486
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002487static const size_t kMonitorsInitial = 32; // Arbitrary.
2488static const size_t kMonitorsMax = 4096; // Arbitrary sanity check.
2489
2490static const size_t kLocalsInitial = 64; // Arbitrary.
2491static const size_t kLocalsMax = 512; // Arbitrary sanity check.
Elliott Hughesbbd76712011-08-17 10:25:24 -07002492
Elliott Hughes515a5bc2011-08-17 11:08:34 -07002493JNIEnvExt::JNIEnvExt(Thread* self, bool check_jni)
Elliott Hughesbbd76712011-08-17 10:25:24 -07002494 : fns(&gNativeInterface),
2495 self(self),
Elliott Hughes515a5bc2011-08-17 11:08:34 -07002496 check_jni(check_jni),
Elliott Hughesbbd76712011-08-17 10:25:24 -07002497 critical(false),
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002498 monitors("monitors", kMonitorsInitial, kMonitorsMax),
2499 locals(kLocalsInitial, kLocalsMax, kLocal) {
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002500}
2501
Carl Shapiroea4dca82011-08-01 13:45:38 -07002502// JNI Invocation interface.
2503
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002504extern "C" jint JNI_CreateJavaVM(JavaVM** p_vm, void** p_env, void* vm_args) {
2505 const JavaVMInitArgs* args = static_cast<JavaVMInitArgs*>(vm_args);
2506 if (args->version < JNI_VERSION_1_2) {
2507 return JNI_EVERSION;
2508 }
2509 Runtime::Options options;
2510 for (int i = 0; i < args->nOptions; ++i) {
2511 JavaVMOption* option = &args->options[i];
Carl Shapirofc322c72011-07-27 00:20:01 -07002512 options.push_back(std::make_pair(StringPiece(option->optionString),
2513 option->extraInfo));
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002514 }
2515 bool ignore_unrecognized = args->ignoreUnrecognized;
Elliott Hughesf2682d52011-08-15 16:37:04 -07002516 Runtime* runtime = Runtime::Create(options, ignore_unrecognized);
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002517 if (runtime == NULL) {
2518 return JNI_ERR;
2519 } else {
2520 *p_env = reinterpret_cast<JNIEnv*>(Thread::Current()->GetJniEnv());
Elliott Hughes0af55432011-08-17 18:37:28 -07002521 *p_vm = reinterpret_cast<JavaVM*>(runtime->GetJavaVM());
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002522 return JNI_OK;
2523 }
2524}
2525
Elliott Hughesf2682d52011-08-15 16:37:04 -07002526extern "C" jint JNI_GetCreatedJavaVMs(JavaVM** vms, jsize, jsize* vm_count) {
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002527 Runtime* runtime = Runtime::Current();
2528 if (runtime == NULL) {
Elliott Hughesf2682d52011-08-15 16:37:04 -07002529 *vm_count = 0;
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002530 } else {
Elliott Hughesf2682d52011-08-15 16:37:04 -07002531 *vm_count = 1;
Elliott Hughes0af55432011-08-17 18:37:28 -07002532 vms[0] = reinterpret_cast<JavaVM*>(runtime->GetJavaVM());
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002533 }
2534 return JNI_OK;
2535}
2536
2537// Historically unsupported.
2538extern "C" jint JNI_GetDefaultJavaVMInitArgs(void* vm_args) {
2539 return JNI_ERR;
2540}
2541
Elliott Hughesf2682d52011-08-15 16:37:04 -07002542jint DestroyJavaVM(JavaVM* vm) {
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002543 if (vm == NULL) {
2544 return JNI_ERR;
2545 } else {
Elliott Hughesf2682d52011-08-15 16:37:04 -07002546 JavaVMExt* raw_vm = reinterpret_cast<JavaVMExt*>(vm);
2547 delete raw_vm->runtime;
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002548 return JNI_OK;
2549 }
2550}
2551
Elliott Hughesf2682d52011-08-15 16:37:04 -07002552jint AttachCurrentThread(JavaVM* vm, JNIEnv** p_env, void* thr_args) {
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002553 if (vm == NULL || p_env == NULL) {
2554 return JNI_ERR;
2555 }
Elliott Hughesf2682d52011-08-15 16:37:04 -07002556 JavaVMExt* raw_vm = reinterpret_cast<JavaVMExt*>(vm);
2557 Runtime* runtime = raw_vm->runtime;
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002558 const char* name = NULL;
2559 if (thr_args != NULL) {
2560 // TODO: check version
2561 name = static_cast<JavaVMAttachArgs*>(thr_args)->name;
2562 // TODO: thread group
2563 }
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002564 bool success = runtime->AttachCurrentThread(name, p_env);
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002565 if (!success) {
2566 return JNI_ERR;
2567 } else {
2568 return JNI_OK;
2569 }
2570}
2571
Elliott Hughesf2682d52011-08-15 16:37:04 -07002572jint DetachCurrentThread(JavaVM* vm) {
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002573 if (vm == NULL) {
2574 return JNI_ERR;
2575 } else {
Elliott Hughesf2682d52011-08-15 16:37:04 -07002576 JavaVMExt* raw_vm = reinterpret_cast<JavaVMExt*>(vm);
2577 Runtime* runtime = raw_vm->runtime;
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002578 runtime->DetachCurrentThread();
2579 return JNI_OK;
2580 }
2581}
2582
Elliott Hughesf2682d52011-08-15 16:37:04 -07002583jint GetEnv(JavaVM* vm, void** env, jint version) {
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002584 if (version < JNI_VERSION_1_1 || version > JNI_VERSION_1_6) {
2585 return JNI_EVERSION;
2586 }
2587 if (vm == NULL || env == NULL) {
2588 return JNI_ERR;
2589 }
2590 Thread* thread = Thread::Current();
2591 if (thread == NULL) {
2592 *env = NULL;
2593 return JNI_EDETACHED;
2594 }
2595 *env = thread->GetJniEnv();
2596 return JNI_OK;
2597}
2598
Elliott Hughesf2682d52011-08-15 16:37:04 -07002599jint AttachCurrentThreadAsDaemon(JavaVM* vm, JNIEnv** p_env, void* thr_args) {
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002600 if (vm == NULL || p_env == NULL) {
2601 return JNI_ERR;
2602 }
Elliott Hughesf2682d52011-08-15 16:37:04 -07002603 JavaVMExt* raw_vm = reinterpret_cast<JavaVMExt*>(vm);
2604 Runtime* runtime = raw_vm->runtime;
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002605 const char* name = NULL;
2606 if (thr_args != NULL) {
2607 // TODO: check version
2608 name = static_cast<JavaVMAttachArgs*>(thr_args)->name;
2609 // TODO: thread group
2610 }
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002611 bool success = runtime->AttachCurrentThreadAsDaemon(name, p_env);
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002612 if (!success) {
2613 return JNI_ERR;
2614 } else {
2615 return JNI_OK;
2616 }
2617}
2618
Elliott Hughesf2682d52011-08-15 16:37:04 -07002619struct JNIInvokeInterface gInvokeInterface = {
Carl Shapiroea4dca82011-08-01 13:45:38 -07002620 NULL, // reserved0
2621 NULL, // reserved1
2622 NULL, // reserved2
2623 DestroyJavaVM,
2624 AttachCurrentThread,
2625 DetachCurrentThread,
2626 GetEnv,
2627 AttachCurrentThreadAsDaemon
2628};
2629
Elliott Hughesbbd76712011-08-17 10:25:24 -07002630static const size_t kPinTableInitialSize = 16;
2631static const size_t kPinTableMaxSize = 1024;
2632
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002633static const size_t kGlobalsInitial = 512; // Arbitrary.
2634static const size_t kGlobalsMax = 51200; // Arbitrary sanity check.
2635
2636static const size_t kWeakGlobalsInitial = 16; // Arbitrary.
2637static const size_t kWeakGlobalsMax = 51200; // Arbitrary sanity check.
2638
Elliott Hughes0af55432011-08-17 18:37:28 -07002639JavaVMExt::JavaVMExt(Runtime* runtime, bool check_jni, bool verbose_jni)
Elliott Hughesbbd76712011-08-17 10:25:24 -07002640 : fns(&gInvokeInterface),
2641 runtime(runtime),
Elliott Hughes515a5bc2011-08-17 11:08:34 -07002642 check_jni(check_jni),
Elliott Hughes0af55432011-08-17 18:37:28 -07002643 verbose_jni(verbose_jni),
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002644 pin_table("pin table", kPinTableInitialSize, kPinTableMaxSize),
Elliott Hughes18c07532011-08-18 15:50:51 -07002645 globals_lock(Mutex::Create("JNI global reference table lock")),
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002646 globals(kGlobalsInitial, kGlobalsMax, kGlobal),
Elliott Hughes18c07532011-08-18 15:50:51 -07002647 weak_globals_lock(Mutex::Create("JNI weak global reference table lock")),
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002648 weak_globals(kWeakGlobalsInitial, kWeakGlobalsMax, kWeakGlobal) {
Elliott Hughesf2682d52011-08-15 16:37:04 -07002649}
2650
Elliott Hughesde69d7f2011-08-18 16:49:37 -07002651JavaVMExt::~JavaVMExt() {
2652 delete globals_lock;
2653 delete weak_globals_lock;
2654}
2655
Ian Rogersdf20fe02011-07-20 20:34:16 -07002656} // namespace art