blob: 9fd0e5fde08ae58cb8dae4b3b7e46bdc55dc00c8 [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);
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700513 // Call the invoke stub associated with the method
514 // Pass everything as arguments
515 const Method::InvokeStub* stub = method->GetInvokeStub();
516 CHECK(stub != NULL);
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700517 JValue result;
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700518 // TODO: we should always have code associated with a method
519 if (method->GetCode()) {
520 (*stub)(method, rcvr, ts.Self(), args, &result);
521 } else {
522 // TODO: pretty print method here
523 LOG(WARNING) << "Not invoking method with no associated code";
524 result.j = 0;
525 }
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700526 return result;
527}
528
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700529JValue InvokeWithJValues(ScopedJniThreadState& ts, jobject obj,
530 jmethodID method_id, jvalue* args) {
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700531 Method* method = reinterpret_cast<Method*>(method_id);
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700532 scoped_array<byte> arg_array(CreateArgArray(ts, method, args));
533 return InvokeWithArgArray(ts, obj, method_id, arg_array.get());
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700534}
535
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700536JValue InvokeWithVarArgs(ScopedJniThreadState& ts, jobject obj,
537 jmethodID method_id, va_list args) {
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700538 Method* method = reinterpret_cast<Method*>(method_id);
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700539 scoped_array<byte> arg_array(CreateArgArray(ts, method, args));
540 return InvokeWithArgArray(ts, obj, method_id, arg_array.get());
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700541}
542
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700543jint GetVersion(JNIEnv* env) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700544 ScopedJniThreadState ts(env);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700545 return JNI_VERSION_1_6;
546}
547
Elliott Hughesb20a5542011-08-12 18:03:12 -0700548jclass DefineClass(JNIEnv* env, const char*, jobject, const jbyte*, jsize) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700549 ScopedJniThreadState ts(env);
Elliott Hughesb20a5542011-08-12 18:03:12 -0700550 LOG(WARNING) << "JNI DefineClass is not supported";
Carl Shapiroea4dca82011-08-01 13:45:38 -0700551 return NULL;
552}
553
Elliott Hughes6b436852011-08-12 10:16:44 -0700554// Section 12.3.2 of the JNI spec describes JNI class descriptors. They're
555// separated with slashes but aren't wrapped with "L;" like regular descriptors
556// (i.e. "a/b/C" rather than "La/b/C;"). Arrays of reference types are an
557// exception; there the "L;" must be present ("[La/b/C;"). Historically we've
558// supported names with dots too (such as "a.b.C").
559std::string NormalizeJniClassDescriptor(const char* name) {
560 std::string result;
561 // Add the missing "L;" if necessary.
562 if (name[0] == '[') {
563 result = name;
564 } else {
565 result += 'L';
566 result += name;
567 result += ';';
568 }
569 // Rewrite '.' as '/' for backwards compatibility.
Elliott Hughesa5b897e2011-08-16 11:33:06 -0700570 if (result.find('.') != std::string::npos) {
571 LOG(WARNING) << "Call to JNI FindClass with dots in name: "
572 << "\"" << name << "\"";
573 std::replace(result.begin(), result.end(), '.', '/');
Elliott Hughes6b436852011-08-12 10:16:44 -0700574 }
575 return result;
576}
577
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700578jclass FindClass(JNIEnv* env, const char* name) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700579 ScopedJniThreadState ts(env);
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700580 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Elliott Hughes6b436852011-08-12 10:16:44 -0700581 std::string descriptor(NormalizeJniClassDescriptor(name));
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700582 // TODO: need to get the appropriate ClassLoader.
Elliott Hughes6b436852011-08-12 10:16:44 -0700583 Class* c = class_linker->FindClass(descriptor, NULL);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -0700584 return AddLocalReference<jclass>(ts, c);
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700585}
586
587jmethodID FromReflectedMethod(JNIEnv* env, jobject method) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700588 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700589 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700590 return NULL;
591}
592
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700593jfieldID FromReflectedField(JNIEnv* env, jobject field) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700594 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700595 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700596 return NULL;
597}
598
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700599jobject ToReflectedMethod(JNIEnv* env, jclass cls,
600 jmethodID methodID, jboolean isStatic) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700601 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700602 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700603 return NULL;
604}
605
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700606jclass GetSuperclass(JNIEnv* env, jclass sub) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700607 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700608 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700609 return NULL;
610}
611
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700612jboolean IsAssignableFrom(JNIEnv* env, jclass sub, jclass sup) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700613 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700614 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700615 return JNI_FALSE;
616}
617
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700618jobject ToReflectedField(JNIEnv* env, jclass cls,
619 jfieldID fieldID, jboolean isStatic) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700620 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700621 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700622 return NULL;
623}
624
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700625jint Throw(JNIEnv* env, jthrowable obj) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700626 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700627 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700628 return 0;
629}
630
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700631jint ThrowNew(JNIEnv* env, jclass clazz, const char* msg) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700632 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700633 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700634 return 0;
635}
636
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700637jthrowable ExceptionOccurred(JNIEnv* env) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700638 ScopedJniThreadState ts(env);
Ian Rogers4dd71f12011-08-16 14:16:02 -0700639 Object* exception = ts.Self()->GetException();
640 if (exception == NULL) {
641 return NULL;
642 } else {
643 // TODO: if adding a local reference failing causes the VM to abort
644 // then the following check will never occur.
645 jthrowable localException = AddLocalReference<jthrowable>(ts, exception);
646 if (localException == NULL) {
647 // We were unable to add a new local reference, and threw a new
648 // exception. We can't return "exception", because it's not a
649 // local reference. So we have to return NULL, indicating that
650 // there was no exception, even though it's pretty much raining
651 // exceptions in here.
652 LOG(WARNING) << "JNI WARNING: addLocal/exception combo";
653 }
654 return localException;
655 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700656}
657
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700658void ExceptionDescribe(JNIEnv* env) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700659 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700660 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700661}
662
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700663void ExceptionClear(JNIEnv* env) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700664 ScopedJniThreadState ts(env);
Elliott Hughesb20a5542011-08-12 18:03:12 -0700665 ts.Self()->ClearException();
Carl Shapiroea4dca82011-08-01 13:45:38 -0700666}
667
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700668void FatalError(JNIEnv* env, const char* msg) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700669 ScopedJniThreadState ts(env);
Elliott Hughesb20a5542011-08-12 18:03:12 -0700670 LOG(FATAL) << "JNI FatalError called: " << msg;
Carl Shapiroea4dca82011-08-01 13:45:38 -0700671}
672
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700673jint PushLocalFrame(JNIEnv* env, jint cap) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700674 ScopedJniThreadState ts(env);
Elliott Hughes0af55432011-08-17 18:37:28 -0700675 UNIMPLEMENTED(WARNING) << "ignoring PushLocalFrame(" << cap << ")";
676 return JNI_OK;
Carl Shapiroea4dca82011-08-01 13:45:38 -0700677}
678
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700679jobject PopLocalFrame(JNIEnv* env, jobject res) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700680 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700681 UNIMPLEMENTED(WARNING) << "ignoring PopLocalFrame " << res;
Elliott Hughes0af55432011-08-17 18:37:28 -0700682 return res;
Carl Shapiroea4dca82011-08-01 13:45:38 -0700683}
684
Elliott Hughes18c07532011-08-18 15:50:51 -0700685jobject NewGlobalRef(JNIEnv* env, jobject obj) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700686 ScopedJniThreadState ts(env);
Elliott Hughes18c07532011-08-18 15:50:51 -0700687 if (obj == NULL) {
688 return NULL;
689 }
690
691 JavaVMExt* vm = Runtime::Current()->GetJavaVM();
692 IndirectReferenceTable& globals = vm->globals;
693 MutexLock mu(vm->globals_lock);
694 IndirectRef ref = globals.Add(IRT_FIRST_SEGMENT, Decode<Object*>(ts, obj));
695 return reinterpret_cast<jobject>(ref);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700696}
697
Elliott Hughes18c07532011-08-18 15:50:51 -0700698void DeleteGlobalRef(JNIEnv* env, jobject obj) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700699 ScopedJniThreadState ts(env);
Elliott Hughes18c07532011-08-18 15:50:51 -0700700 if (obj == NULL) {
701 return;
702 }
703
704 JavaVMExt* vm = Runtime::Current()->GetJavaVM();
705 IndirectReferenceTable& globals = vm->globals;
706 MutexLock mu(vm->globals_lock);
707
708 if (!globals.Remove(IRT_FIRST_SEGMENT, obj)) {
709 LOG(WARNING) << "JNI WARNING: DeleteGlobalRef(" << obj << ") "
710 << "failed to find entry";
711 }
712}
713
714jweak NewWeakGlobalRef(JNIEnv* env, jobject obj) {
715 ScopedJniThreadState ts(env);
716 if (obj == NULL) {
717 return NULL;
718 }
719
720 JavaVMExt* vm = Runtime::Current()->GetJavaVM();
721 IndirectReferenceTable& weak_globals = vm->weak_globals;
722 MutexLock mu(vm->weak_globals_lock);
723 IndirectRef ref = weak_globals.Add(IRT_FIRST_SEGMENT, Decode<Object*>(ts, obj));
724 return reinterpret_cast<jobject>(ref);
725}
726
727void DeleteWeakGlobalRef(JNIEnv* env, jweak obj) {
728 ScopedJniThreadState ts(env);
729 if (obj == NULL) {
730 return;
731 }
732
733 JavaVMExt* vm = Runtime::Current()->GetJavaVM();
734 IndirectReferenceTable& weak_globals = vm->weak_globals;
735 MutexLock mu(vm->weak_globals_lock);
736
737 if (!weak_globals.Remove(IRT_FIRST_SEGMENT, obj)) {
738 LOG(WARNING) << "JNI WARNING: DeleteWeakGlobalRef(" << obj << ") "
739 << "failed to find entry";
740 }
741}
742
743jobject NewLocalRef(JNIEnv* env, jobject obj) {
744 ScopedJniThreadState ts(env);
745 if (obj == NULL) {
746 return NULL;
747 }
748
749 IndirectReferenceTable& locals = ts.Env()->locals;
750
751 uint32_t cookie = IRT_FIRST_SEGMENT; // TODO
752 IndirectRef ref = locals.Add(cookie, Decode<Object*>(ts, obj));
753 return reinterpret_cast<jobject>(ref);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700754}
755
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700756void DeleteLocalRef(JNIEnv* env, jobject obj) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700757 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700758 if (obj == NULL) {
759 return;
760 }
761
762 IndirectReferenceTable& locals = ts.Env()->locals;
763
764 uint32_t cookie = IRT_FIRST_SEGMENT; // TODO
765 if (!locals.Remove(cookie, obj)) {
766 // Attempting to delete a local reference that is not in the
767 // topmost local reference frame is a no-op. DeleteLocalRef returns
768 // void and doesn't throw any exceptions, but we should probably
769 // complain about it so the user will notice that things aren't
770 // going quite the way they expect.
771 LOG(WARNING) << "JNI WARNING: DeleteLocalRef(" << obj << ") "
772 << "failed to find entry";
773 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700774}
775
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700776jboolean IsSameObject(JNIEnv* env, jobject obj1, jobject obj2) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700777 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700778 return (Decode<Object*>(ts, obj1) == Decode<Object*>(ts, obj2))
779 ? JNI_TRUE : JNI_FALSE;
Carl Shapiroea4dca82011-08-01 13:45:38 -0700780}
781
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700782jint EnsureLocalCapacity(JNIEnv* env, jint) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700783 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700784 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700785 return 0;
786}
787
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700788jobject AllocObject(JNIEnv* env, jclass clazz) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700789 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700790 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700791 return NULL;
792}
793
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700794jobject NewObject(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700795 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700796 va_list args;
797 va_start(args, methodID);
798 jobject result = NewObjectV(env, clazz, methodID, args);
799 va_end(args);
800 return result;
Carl Shapiroea4dca82011-08-01 13:45:38 -0700801}
802
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700803jobject NewObjectV(JNIEnv* env,
804 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700805 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700806 Class* klass = Decode<Class*>(ts, clazz);
807 Object* result = klass->NewInstance();
808 jobject local_result = AddLocalReference<jobject>(ts, result);
809 CallNonvirtualVoidMethodV(env, local_result, clazz, methodID, args);
810 return local_result;
Carl Shapiroea4dca82011-08-01 13:45:38 -0700811}
812
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700813jobject NewObjectA(JNIEnv* env,
814 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700815 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700816 Class* klass = Decode<Class*>(ts, clazz);
817 Object* result = klass->NewInstance();
818 jobject local_result = AddLocalReference<jobjectArray>(ts, result);
819 CallNonvirtualVoidMethodA(env, local_result, clazz, methodID, args);
820 return local_result;
Carl Shapiroea4dca82011-08-01 13:45:38 -0700821}
822
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700823jclass GetObjectClass(JNIEnv* env, jobject obj) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700824 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700825 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700826 return NULL;
827}
828
Ian Rogers4dd71f12011-08-16 14:16:02 -0700829jboolean IsInstanceOf(JNIEnv* env, jobject jobj, jclass clazz) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700830 ScopedJniThreadState ts(env);
Ian Rogers4dd71f12011-08-16 14:16:02 -0700831 CHECK_NE(static_cast<jclass>(NULL), clazz);
832 if (jobj == NULL) {
833 // NB. JNI is different from regular Java instanceof in this respect
834 return JNI_TRUE;
835 } else {
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700836 Object* obj = Decode<Object*>(ts, jobj);
837 Class* klass = Decode<Class*>(ts, clazz);
Ian Rogers4dd71f12011-08-16 14:16:02 -0700838 return Object::InstanceOf(obj, klass) ? JNI_TRUE : JNI_FALSE;
839 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700840}
841
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700842jmethodID GetMethodID(JNIEnv* env,
843 jclass clazz, const char* name, const char* sig) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700844 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700845 Class* klass = Decode<Class*>(ts, clazz);
Carl Shapiro83ab4f32011-08-15 20:21:39 -0700846 if (!klass->IsInitialized()) {
847 // TODO: initialize the class
848 }
849 Method* method = klass->FindVirtualMethod(name, sig);
850 if (method == NULL) {
851 // No virtual method matching the signature. Search declared
852 // private methods and constructors.
853 method = klass->FindDeclaredDirectMethod(name, sig);
854 }
Ian Rogers4dd71f12011-08-16 14:16:02 -0700855 if (method == NULL) {
856 Thread* self = Thread::Current();
857 std::string class_name = klass->GetDescriptor().ToString();
858 // TODO: pretty print method names through a single routine
859 self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
860 "no method \"%s.%s%s\"",
861 class_name.c_str(), name, sig);
Carl Shapiro83ab4f32011-08-15 20:21:39 -0700862 return NULL;
Ian Rogers4dd71f12011-08-16 14:16:02 -0700863 } else if (method->IsStatic()) {
864 Thread* self = Thread::Current();
865 std::string class_name = klass->GetDescriptor().ToString();
866 // TODO: pretty print method names through a single routine
867 self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
868 "method \"%s.%s%s\" is static",
869 class_name.c_str(), name, sig);
Carl Shapiro83ab4f32011-08-15 20:21:39 -0700870 return NULL;
Ian Rogers4dd71f12011-08-16 14:16:02 -0700871 } else {
872 // TODO: create a JNI weak global reference for method
873 bool success = EnsureInvokeStub(method);
874 if (!success) {
875 // TODO: throw OutOfMemoryException
876 return NULL;
877 }
878 return reinterpret_cast<jmethodID>(method);
Carl Shapiro83ab4f32011-08-15 20:21:39 -0700879 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700880}
881
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700882jobject CallObjectMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700883 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700884 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700885 return NULL;
886}
887
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700888jobject CallObjectMethodV(JNIEnv* env,
889 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700890 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700891 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700892 return NULL;
893}
894
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700895jobject CallObjectMethodA(JNIEnv* env,
896 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700897 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700898 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700899 return NULL;
900}
901
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700902jboolean CallBooleanMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700903 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700904 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700905 return JNI_FALSE;
906}
907
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700908jboolean CallBooleanMethodV(JNIEnv* env,
909 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700910 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700911 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700912 return JNI_FALSE;
913}
914
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700915jboolean CallBooleanMethodA(JNIEnv* env,
916 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700917 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700918 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700919 return JNI_FALSE;
920}
921
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700922jbyte CallByteMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700923 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700924 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700925 return 0;
926}
927
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700928jbyte CallByteMethodV(JNIEnv* env,
929 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700930 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700931 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700932 return 0;
933}
934
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700935jbyte CallByteMethodA(JNIEnv* env,
936 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700937 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700938 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700939 return 0;
940}
941
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700942jchar CallCharMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700943 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700944 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700945 return 0;
946}
947
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700948jchar CallCharMethodV(JNIEnv* env,
949 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700950 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700951 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700952 return 0;
953}
954
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700955jchar CallCharMethodA(JNIEnv* env,
956 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700957 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700958 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700959 return 0;
960}
961
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700962jshort CallShortMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700963 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700964 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700965 return 0;
966}
967
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700968jshort CallShortMethodV(JNIEnv* env,
969 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700970 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700971 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700972 return 0;
973}
974
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700975jshort CallShortMethodA(JNIEnv* env,
976 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700977 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700978 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700979 return 0;
980}
981
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700982jint CallIntMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700983 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700984 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700985 return 0;
986}
987
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700988jint CallIntMethodV(JNIEnv* env,
989 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700990 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700991 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700992 return 0;
993}
994
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700995jint CallIntMethodA(JNIEnv* env,
996 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700997 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700998 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700999 return 0;
1000}
1001
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001002jlong CallLongMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001003 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001004 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001005 return 0;
1006}
1007
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001008jlong CallLongMethodV(JNIEnv* env,
1009 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001010 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001011 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001012 return 0;
1013}
1014
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001015jlong CallLongMethodA(JNIEnv* env,
1016 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001017 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001018 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001019 return 0;
1020}
1021
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001022jfloat CallFloatMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001023 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001024 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001025 return 0;
1026}
1027
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001028jfloat CallFloatMethodV(JNIEnv* env,
1029 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001030 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001031 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001032 return 0;
1033}
1034
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001035jfloat CallFloatMethodA(JNIEnv* env,
1036 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001037 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001038 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001039 return 0;
1040}
1041
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001042jdouble CallDoubleMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001043 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001044 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001045 return 0;
1046}
1047
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001048jdouble CallDoubleMethodV(JNIEnv* env,
1049 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001050 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001051 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001052 return 0;
1053}
1054
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001055jdouble CallDoubleMethodA(JNIEnv* env,
1056 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001057 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001058 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001059 return 0;
1060}
1061
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001062void CallVoidMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001063 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001064 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001065}
1066
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001067void CallVoidMethodV(JNIEnv* env, jobject obj,
1068 jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001069 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001070 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001071}
1072
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001073void CallVoidMethodA(JNIEnv* env, jobject obj,
1074 jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001075 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001076 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001077}
1078
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001079jobject CallNonvirtualObjectMethod(JNIEnv* env,
1080 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001081 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001082 va_list ap;
1083 va_start(ap, methodID);
1084 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1085 jobject local_result = AddLocalReference<jobject>(ts, result.l);
1086 va_end(ap);
1087 return local_result;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001088}
1089
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001090jobject CallNonvirtualObjectMethodV(JNIEnv* env,
1091 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001092 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001093 JValue result = InvokeWithVarArgs(ts, obj, methodID, args);
1094 return AddLocalReference<jobject>(ts, result.l);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001095}
1096
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001097jobject CallNonvirtualObjectMethodA(JNIEnv* env,
1098 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001099 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001100 JValue result = InvokeWithJValues(ts, obj, methodID, args);
1101 return AddLocalReference<jobject>(ts, result.l);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001102}
1103
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001104jboolean CallNonvirtualBooleanMethod(JNIEnv* env,
1105 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001106 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001107 va_list ap;
1108 va_start(ap, methodID);
1109 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1110 va_end(ap);
1111 return result.z;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001112}
1113
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001114jboolean CallNonvirtualBooleanMethodV(JNIEnv* env,
1115 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001116 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001117 return InvokeWithVarArgs(ts, obj, methodID, args).z;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001118}
1119
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001120jboolean CallNonvirtualBooleanMethodA(JNIEnv* env,
1121 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001122 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001123 return InvokeWithJValues(ts, obj, methodID, args).z;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001124}
1125
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001126jbyte CallNonvirtualByteMethod(JNIEnv* env,
1127 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001128 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001129 va_list ap;
1130 va_start(ap, methodID);
1131 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1132 va_end(ap);
1133 return result.b;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001134}
1135
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001136jbyte CallNonvirtualByteMethodV(JNIEnv* env,
1137 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001138 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001139 return InvokeWithVarArgs(ts, obj, methodID, args).b;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001140}
1141
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001142jbyte CallNonvirtualByteMethodA(JNIEnv* env,
1143 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001144 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001145 return InvokeWithJValues(ts, obj, methodID, args).b;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001146}
1147
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001148jchar CallNonvirtualCharMethod(JNIEnv* env,
1149 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001150 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001151 va_list ap;
1152 va_start(ap, methodID);
1153 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1154 va_end(ap);
1155 return result.c;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001156}
1157
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001158jchar CallNonvirtualCharMethodV(JNIEnv* env,
1159 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001160 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001161 return InvokeWithVarArgs(ts, obj, methodID, args).c;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001162}
1163
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001164jchar CallNonvirtualCharMethodA(JNIEnv* env,
1165 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001166 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001167 return InvokeWithJValues(ts, obj, methodID, args).c;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001168}
1169
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001170jshort CallNonvirtualShortMethod(JNIEnv* env,
1171 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001172 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001173 va_list ap;
1174 va_start(ap, methodID);
1175 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1176 va_end(ap);
1177 return result.s;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001178}
1179
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001180jshort CallNonvirtualShortMethodV(JNIEnv* env,
1181 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001182 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001183 return InvokeWithVarArgs(ts, obj, methodID, args).s;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001184}
1185
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001186jshort CallNonvirtualShortMethodA(JNIEnv* env,
1187 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001188 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001189 return InvokeWithJValues(ts, obj, methodID, args).s;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001190}
1191
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001192jint CallNonvirtualIntMethod(JNIEnv* env,
1193 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001194 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001195 va_list ap;
1196 va_start(ap, methodID);
1197 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1198 va_end(ap);
1199 return result.i;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001200}
1201
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001202jint CallNonvirtualIntMethodV(JNIEnv* env,
1203 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001204 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001205 return InvokeWithVarArgs(ts, obj, methodID, args).i;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001206}
1207
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001208jint CallNonvirtualIntMethodA(JNIEnv* env,
1209 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001210 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001211 return InvokeWithJValues(ts, obj, methodID, args).i;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001212}
1213
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001214jlong CallNonvirtualLongMethod(JNIEnv* env,
1215 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001216 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001217 va_list ap;
1218 va_start(ap, methodID);
1219 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1220 va_end(ap);
1221 return result.j;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001222}
1223
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001224jlong CallNonvirtualLongMethodV(JNIEnv* env,
1225 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001226 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001227 return InvokeWithVarArgs(ts, obj, methodID, args).j;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001228}
1229
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001230jlong CallNonvirtualLongMethodA(JNIEnv* env,
1231 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001232 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001233 return InvokeWithJValues(ts, obj, methodID, args).j;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001234}
1235
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001236jfloat CallNonvirtualFloatMethod(JNIEnv* env,
1237 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001238 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001239 va_list ap;
1240 va_start(ap, methodID);
1241 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1242 va_end(ap);
1243 return result.f;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001244}
1245
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001246jfloat CallNonvirtualFloatMethodV(JNIEnv* env,
1247 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001248 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001249 return InvokeWithVarArgs(ts, obj, methodID, args).f;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001250}
1251
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001252jfloat CallNonvirtualFloatMethodA(JNIEnv* env,
1253 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001254 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001255 return InvokeWithJValues(ts, obj, methodID, args).f;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001256}
1257
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001258jdouble CallNonvirtualDoubleMethod(JNIEnv* env,
1259 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001260 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001261 va_list ap;
1262 va_start(ap, methodID);
1263 JValue result = InvokeWithVarArgs(ts, obj, methodID, ap);
1264 va_end(ap);
1265 return result.d;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001266}
1267
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001268jdouble CallNonvirtualDoubleMethodV(JNIEnv* env,
1269 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001270 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001271 return InvokeWithVarArgs(ts, obj, methodID, args).d;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001272}
1273
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001274jdouble CallNonvirtualDoubleMethodA(JNIEnv* env,
1275 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001276 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001277 return InvokeWithJValues(ts, obj, methodID, args).d;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001278}
1279
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001280void CallNonvirtualVoidMethod(JNIEnv* env,
1281 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001282 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001283 va_list ap;
1284 va_start(ap, methodID);
1285 InvokeWithVarArgs(ts, obj, methodID, ap);
1286 va_end(ap);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001287}
1288
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001289void CallNonvirtualVoidMethodV(JNIEnv* env,
1290 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001291 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001292 InvokeWithVarArgs(ts, obj, methodID, args);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001293}
1294
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001295void CallNonvirtualVoidMethodA(JNIEnv* env,
1296 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001297 ScopedJniThreadState ts(env);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001298 InvokeWithJValues(ts, obj, methodID, args);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001299}
1300
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001301jfieldID GetFieldID(JNIEnv* env,
1302 jclass clazz, const char* name, const char* sig) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001303 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001304 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001305 return NULL;
1306}
1307
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001308jobject GetObjectField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001309 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001310 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001311 return NULL;
1312}
1313
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001314jboolean GetBooleanField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001315 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001316 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001317 return JNI_FALSE;
1318}
1319
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001320jbyte GetByteField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001321 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001322 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001323 return 0;
1324}
1325
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001326jchar GetCharField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001327 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001328 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001329 return 0;
1330}
1331
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001332jshort GetShortField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001333 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001334 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001335 return 0;
1336}
1337
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001338jint GetIntField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001339 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001340 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001341 return 0;
1342}
1343
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001344jlong GetLongField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001345 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001346 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001347 return 0;
1348}
1349
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001350jfloat GetFloatField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001351 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001352 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001353 return 0;
1354}
1355
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001356jdouble GetDoubleField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001357 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001358 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001359 return 0;
1360}
1361
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001362void SetObjectField(JNIEnv* env, jobject obj, jfieldID fieldID, jobject val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001363 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001364 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001365}
1366
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001367void SetBooleanField(JNIEnv* env, jobject obj, jfieldID fieldID, jboolean val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001368 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001369 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001370}
1371
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001372void SetByteField(JNIEnv* env, jobject obj, jfieldID fieldID, jbyte val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001373 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001374 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001375}
1376
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001377void SetCharField(JNIEnv* env, jobject obj, jfieldID fieldID, jchar val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001378 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001379 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001380}
1381
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001382void SetShortField(JNIEnv* env, jobject obj, jfieldID fieldID, jshort val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001383 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001384 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001385}
1386
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001387void SetIntField(JNIEnv* env, jobject obj, jfieldID fieldID, jint val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001388 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001389 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001390}
1391
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001392void SetLongField(JNIEnv* env, jobject obj, jfieldID fieldID, jlong val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001393 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001394 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001395}
1396
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001397void SetFloatField(JNIEnv* env, jobject obj, jfieldID fieldID, jfloat val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001398 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001399 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001400}
1401
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001402void SetDoubleField(JNIEnv* env, jobject obj, jfieldID fieldID, jdouble val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001403 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001404 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001405}
1406
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001407jmethodID GetStaticMethodID(JNIEnv* env,
1408 jclass clazz, const char* name, const char* sig) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001409 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001410 Class* klass = Decode<Class*>(ts, clazz);
Carl Shapiro83ab4f32011-08-15 20:21:39 -07001411 if (!klass->IsInitialized()) {
1412 // TODO: initialize the class
1413 }
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001414 Method* method = klass->FindDirectMethod(name, sig);
Ian Rogers4dd71f12011-08-16 14:16:02 -07001415 if (method == NULL) {
1416 Thread* self = Thread::Current();
1417 std::string class_name = klass->GetDescriptor().ToString();
1418 // TODO: pretty print method names through a single routine
1419 // TODO: may want to FindVirtualMethod to give more informative error
1420 // message here
1421 self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
1422 "no method \"%s.%s%s\"",
1423 class_name.c_str(), name, sig);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001424 return NULL;
Ian Rogers4dd71f12011-08-16 14:16:02 -07001425 } else if (!method->IsStatic()) {
1426 Thread* self = Thread::Current();
1427 std::string class_name = klass->GetDescriptor().ToString();
1428 // TODO: pretty print method names through a single routine
1429 self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
1430 "method \"%s.%s%s\" is not static",
1431 class_name.c_str(), name, sig);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001432 return NULL;
Ian Rogers4dd71f12011-08-16 14:16:02 -07001433 } else {
1434 // TODO: create a JNI weak global reference for method
1435 bool success = EnsureInvokeStub(method);
1436 if (!success) {
1437 // TODO: throw OutOfMemoryException
1438 return NULL;
1439 }
1440 return reinterpret_cast<jmethodID>(method);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001441 }
Carl Shapiroea4dca82011-08-01 13:45:38 -07001442}
1443
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001444jobject CallStaticObjectMethod(JNIEnv* env,
1445 jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001446 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001447 va_list ap;
1448 va_start(ap, methodID);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001449 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001450 jobject local_result = AddLocalReference<jobject>(ts, result.l);
1451 va_end(ap);
1452 return local_result;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001453}
1454
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001455jobject CallStaticObjectMethodV(JNIEnv* env,
1456 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001457 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001458 JValue result = InvokeWithVarArgs(ts, NULL, methodID, args);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001459 return AddLocalReference<jobject>(ts, result.l);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001460}
1461
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001462jobject CallStaticObjectMethodA(JNIEnv* env,
1463 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001464 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001465 JValue result = InvokeWithJValues(ts, NULL, methodID, args);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001466 return AddLocalReference<jobject>(ts, result.l);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001467}
1468
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001469jboolean CallStaticBooleanMethod(JNIEnv* env,
1470 jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001471 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001472 va_list ap;
1473 va_start(ap, methodID);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001474 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1475 va_end(ap);
1476 return result.z;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001477}
1478
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001479jboolean CallStaticBooleanMethodV(JNIEnv* env,
1480 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001481 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001482 return InvokeWithVarArgs(ts, NULL, methodID, args).z;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001483}
1484
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001485jboolean CallStaticBooleanMethodA(JNIEnv* env,
1486 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001487 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001488 return InvokeWithJValues(ts, NULL, methodID, args).z;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001489}
1490
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001491jbyte CallStaticByteMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001492 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001493 va_list ap;
1494 va_start(ap, methodID);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001495 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1496 va_end(ap);
1497 return result.b;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001498}
1499
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001500jbyte CallStaticByteMethodV(JNIEnv* env,
1501 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001502 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001503 return InvokeWithVarArgs(ts, NULL, methodID, args).b;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001504}
1505
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001506jbyte CallStaticByteMethodA(JNIEnv* env,
1507 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001508 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001509 return InvokeWithJValues(ts, NULL, methodID, args).b;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001510}
1511
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001512jchar CallStaticCharMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001513 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001514 va_list ap;
1515 va_start(ap, methodID);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001516 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1517 va_end(ap);
1518 return result.c;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001519}
1520
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001521jchar CallStaticCharMethodV(JNIEnv* env,
1522 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001523 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001524 return InvokeWithVarArgs(ts, NULL, methodID, args).c;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001525}
1526
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001527jchar CallStaticCharMethodA(JNIEnv* env,
1528 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001529 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001530 return InvokeWithJValues(ts, NULL, methodID, args).c;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001531}
1532
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001533jshort CallStaticShortMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001534 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001535 va_list ap;
1536 va_start(ap, methodID);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001537 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1538 va_end(ap);
1539 return result.s;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001540}
1541
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001542jshort CallStaticShortMethodV(JNIEnv* env,
1543 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001544 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001545 return InvokeWithVarArgs(ts, NULL, methodID, args).s;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001546}
1547
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001548jshort CallStaticShortMethodA(JNIEnv* env,
1549 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001550 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001551 return InvokeWithJValues(ts, NULL, methodID, args).s;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001552}
1553
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001554jint CallStaticIntMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001555 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001556 va_list ap;
1557 va_start(ap, methodID);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001558 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1559 va_end(ap);
1560 return result.i;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001561}
1562
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001563jint CallStaticIntMethodV(JNIEnv* env,
1564 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001565 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001566 return InvokeWithVarArgs(ts, NULL, methodID, args).i;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001567}
1568
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001569jint CallStaticIntMethodA(JNIEnv* env,
1570 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001571 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001572 return InvokeWithJValues(ts, NULL, methodID, args).i;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001573}
1574
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001575jlong CallStaticLongMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001576 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001577 va_list ap;
1578 va_start(ap, methodID);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001579 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1580 va_end(ap);
1581 return result.j;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001582}
1583
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001584jlong CallStaticLongMethodV(JNIEnv* env,
1585 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001586 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001587 return InvokeWithVarArgs(ts, NULL, methodID, args).j;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001588}
1589
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001590jlong CallStaticLongMethodA(JNIEnv* env,
1591 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001592 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001593 return InvokeWithJValues(ts, NULL, methodID, args).j;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001594}
1595
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001596jfloat CallStaticFloatMethod(JNIEnv* env, jclass cls, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001597 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001598 va_list ap;
1599 va_start(ap, methodID);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001600 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1601 va_end(ap);
1602 return result.f;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001603}
1604
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001605jfloat CallStaticFloatMethodV(JNIEnv* env,
1606 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001607 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001608 return InvokeWithVarArgs(ts, NULL, methodID, args).f;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001609}
1610
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001611jfloat CallStaticFloatMethodA(JNIEnv* env,
1612 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001613 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001614 return InvokeWithJValues(ts, NULL, methodID, args).f;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001615}
1616
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001617jdouble CallStaticDoubleMethod(JNIEnv* env, jclass cls, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001618 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001619 va_list ap;
1620 va_start(ap, methodID);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001621 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
1622 va_end(ap);
1623 return result.d;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001624}
1625
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001626jdouble CallStaticDoubleMethodV(JNIEnv* env,
1627 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001628 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001629 return InvokeWithVarArgs(ts, NULL, methodID, args).d;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001630}
1631
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001632jdouble CallStaticDoubleMethodA(JNIEnv* env,
1633 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001634 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001635 return InvokeWithJValues(ts, NULL, methodID, args).d;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001636}
1637
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001638void CallStaticVoidMethod(JNIEnv* env, jclass cls, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001639 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001640 va_list ap;
1641 va_start(ap, methodID);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001642 InvokeWithVarArgs(ts, NULL, methodID, ap);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001643 va_end(ap);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001644}
1645
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001646void CallStaticVoidMethodV(JNIEnv* env,
1647 jclass cls, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001648 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001649 InvokeWithVarArgs(ts, NULL, methodID, args);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001650}
1651
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001652void CallStaticVoidMethodA(JNIEnv* env,
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001653 jclass cls, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001654 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001655 InvokeWithJValues(ts, NULL, methodID, args);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001656}
1657
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001658jfieldID GetStaticFieldID(JNIEnv* env,
1659 jclass clazz, const char* name, const char* sig) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001660 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001661 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001662 return 0;
1663}
1664
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001665jobject GetStaticObjectField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001666 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001667 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001668 return NULL;
1669}
1670
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001671jboolean GetStaticBooleanField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001672 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001673 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001674 return JNI_FALSE;
1675}
1676
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001677jbyte GetStaticByteField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001678 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001679 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001680 return 0;
1681}
1682
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001683jchar GetStaticCharField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001684 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001685 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001686 return 0;
1687}
1688
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001689jshort GetStaticShortField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001690 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001691 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001692 return 0;
1693}
1694
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001695jint GetStaticIntField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001696 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001697 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001698 return 0;
1699}
1700
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001701jlong GetStaticLongField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001702 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001703 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001704 return 0;
1705}
1706
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001707jfloat GetStaticFloatField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001708 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001709 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001710 return 0;
1711}
1712
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001713jdouble GetStaticDoubleField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001714 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001715 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001716 return 0;
1717}
1718
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001719void SetStaticObjectField(JNIEnv* env,
1720 jclass clazz, jfieldID fieldID, jobject value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001721 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001722 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001723}
1724
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001725void SetStaticBooleanField(JNIEnv* env,
1726 jclass clazz, jfieldID fieldID, jboolean value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001727 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001728 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001729}
1730
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001731void SetStaticByteField(JNIEnv* env,
1732 jclass clazz, jfieldID fieldID, jbyte value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001733 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001734 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001735}
1736
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001737void SetStaticCharField(JNIEnv* env,
1738 jclass clazz, jfieldID fieldID, jchar value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001739 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001740 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001741}
1742
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001743void SetStaticShortField(JNIEnv* env,
1744 jclass clazz, jfieldID fieldID, jshort value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001745 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001746 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001747}
1748
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001749void SetStaticIntField(JNIEnv* env,
1750 jclass clazz, jfieldID fieldID, jint value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001751 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001752 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001753}
1754
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001755void SetStaticLongField(JNIEnv* env,
1756 jclass clazz, jfieldID fieldID, jlong value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001757 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001758 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001759}
1760
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001761void SetStaticFloatField(JNIEnv* env,
1762 jclass clazz, jfieldID fieldID, jfloat value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001763 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001764 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001765}
1766
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001767void SetStaticDoubleField(JNIEnv* env,
1768 jclass clazz, jfieldID fieldID, jdouble value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001769 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001770 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001771}
1772
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001773jstring NewString(JNIEnv* env, const jchar* unicode, jsize len) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001774 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001775 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001776 return NULL;
1777}
1778
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001779jsize GetStringLength(JNIEnv* env, jstring str) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001780 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001781 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001782 return 0;
1783}
1784
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001785const jchar* GetStringChars(JNIEnv* env, jstring str, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001786 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001787 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001788 return NULL;
1789}
1790
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001791void ReleaseStringChars(JNIEnv* env, jstring str, const jchar* chars) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001792 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001793 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001794}
1795
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001796jstring NewStringUTF(JNIEnv* env, const char* utf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001797 ScopedJniThreadState ts(env);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001798 if (utf == NULL) {
1799 return NULL;
1800 }
Elliott Hughesbfaadc82011-08-18 17:36:58 -07001801 String* result = String::AllocFromModifiedUtf8(utf);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001802 return AddLocalReference<jstring>(ts, result);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001803}
1804
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001805jsize GetStringUTFLength(JNIEnv* env, jstring str) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001806 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001807 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001808 return 0;
1809}
1810
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001811const char* GetStringUTFChars(JNIEnv* env, jstring str, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001812 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001813 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001814 return NULL;
1815}
1816
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001817void ReleaseStringUTFChars(JNIEnv* env, jstring str, const char* chars) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001818 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001819 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001820}
1821
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001822jsize GetArrayLength(JNIEnv* env, jarray array) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001823 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001824 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001825 return 0;
1826}
1827
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001828jobject GetObjectArrayElement(JNIEnv* env, jobjectArray array, jsize index) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001829 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001830 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001831 return NULL;
1832}
1833
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001834void SetObjectArrayElement(JNIEnv* env,
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001835 jobjectArray java_array, jsize index, jobject java_value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001836 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001837 ObjectArray<Object>* array = Decode<ObjectArray<Object>*>(ts, java_array);
1838 Object* value = Decode<Object*>(ts, java_value);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001839 array->Set(index, value);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001840}
1841
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001842template<typename JniT, typename ArtT>
1843JniT NewPrimitiveArray(ScopedJniThreadState& ts, jsize length) {
1844 CHECK_GE(length, 0); // TODO: ReportJniError
1845 ArtT* result = ArtT::Alloc(length);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001846 return AddLocalReference<JniT>(ts, result);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001847}
1848
Elliott Hughesf2682d52011-08-15 16:37:04 -07001849jbooleanArray NewBooleanArray(JNIEnv* env, jsize length) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001850 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001851 return NewPrimitiveArray<jbooleanArray, BooleanArray>(ts, length);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001852}
1853
Elliott Hughesf2682d52011-08-15 16:37:04 -07001854jbyteArray NewByteArray(JNIEnv* env, jsize length) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001855 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001856 return NewPrimitiveArray<jbyteArray, ByteArray>(ts, length);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001857}
1858
Elliott Hughesf2682d52011-08-15 16:37:04 -07001859jcharArray NewCharArray(JNIEnv* env, jsize length) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001860 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001861 return NewPrimitiveArray<jcharArray, CharArray>(ts, length);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001862}
1863
Elliott Hughesf2682d52011-08-15 16:37:04 -07001864jdoubleArray NewDoubleArray(JNIEnv* env, jsize length) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001865 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001866 return NewPrimitiveArray<jdoubleArray, DoubleArray>(ts, length);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001867}
1868
Elliott Hughesf2682d52011-08-15 16:37:04 -07001869jfloatArray NewFloatArray(JNIEnv* env, jsize length) {
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001870 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001871 return NewPrimitiveArray<jfloatArray, FloatArray>(ts, length);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001872}
1873
Elliott Hughesf2682d52011-08-15 16:37:04 -07001874jintArray NewIntArray(JNIEnv* env, jsize length) {
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001875 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001876 return NewPrimitiveArray<jintArray, IntArray>(ts, length);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001877}
1878
Elliott Hughesf2682d52011-08-15 16:37:04 -07001879jlongArray NewLongArray(JNIEnv* env, jsize length) {
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001880 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001881 return NewPrimitiveArray<jlongArray, LongArray>(ts, length);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001882}
1883
Elliott Hughesf2682d52011-08-15 16:37:04 -07001884jobjectArray NewObjectArray(JNIEnv* env, jsize length, jclass element_jclass, jobject initial_element) {
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001885 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001886 CHECK_GE(length, 0); // TODO: ReportJniError
1887
1888 // Compute the array class corresponding to the given element class.
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001889 Class* element_class = Decode<Class*>(ts, element_jclass);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001890 std::string descriptor;
1891 descriptor += "[";
1892 descriptor += element_class->GetDescriptor().ToString();
1893
1894 // Find the class.
1895 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
1896 // TODO: need to get the appropriate ClassLoader.
1897 Class* array_class = class_linker->FindClass(descriptor, NULL);
1898 if (array_class == NULL) {
1899 return NULL;
1900 }
1901
1902 ObjectArray<Object>* result = ObjectArray<Object>::Alloc(array_class, length);
1903 CHECK(initial_element == NULL); // TODO: support initial_element
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001904 return AddLocalReference<jobjectArray>(ts, result);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001905}
1906
1907jshortArray NewShortArray(JNIEnv* env, jsize length) {
1908 ScopedJniThreadState ts(env);
1909 return NewPrimitiveArray<jshortArray, ShortArray>(ts, length);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001910}
1911
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001912jboolean* GetBooleanArrayElements(JNIEnv* env,
1913 jbooleanArray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001914 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001915 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001916 return NULL;
1917}
1918
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001919jbyte* GetByteArrayElements(JNIEnv* env, jbyteArray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001920 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001921 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001922 return NULL;
1923}
1924
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001925jchar* GetCharArrayElements(JNIEnv* env, jcharArray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001926 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001927 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001928 return NULL;
1929}
1930
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001931jshort* GetShortArrayElements(JNIEnv* env,
1932 jshortArray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001933 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001934 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001935 return NULL;
1936}
1937
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001938jint* GetIntArrayElements(JNIEnv* env, jintArray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001939 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001940 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001941 return NULL;
1942}
1943
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001944jlong* GetLongArrayElements(JNIEnv* env, jlongArray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001945 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001946 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001947 return NULL;
1948}
1949
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001950jfloat* GetFloatArrayElements(JNIEnv* env,
1951 jfloatArray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001952 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001953 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001954 return NULL;
1955}
1956
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001957jdouble* GetDoubleArrayElements(JNIEnv* env,
1958 jdoubleArray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001959 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001960 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001961 return NULL;
1962}
1963
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001964void ReleaseBooleanArrayElements(JNIEnv* env,
1965 jbooleanArray array, jboolean* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001966 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001967 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001968}
1969
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001970void ReleaseByteArrayElements(JNIEnv* env,
1971 jbyteArray array, jbyte* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001972 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001973 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001974}
1975
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001976void ReleaseCharArrayElements(JNIEnv* env,
1977 jcharArray array, jchar* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001978 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001979 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001980}
1981
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001982void ReleaseShortArrayElements(JNIEnv* env,
1983 jshortArray array, jshort* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001984 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001985 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001986}
1987
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001988void ReleaseIntArrayElements(JNIEnv* env,
1989 jintArray array, jint* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001990 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001991 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001992}
1993
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001994void ReleaseLongArrayElements(JNIEnv* env,
1995 jlongArray array, jlong* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001996 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001997 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001998}
1999
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002000void ReleaseFloatArrayElements(JNIEnv* env,
2001 jfloatArray array, jfloat* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002002 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002003 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002004}
2005
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002006void ReleaseDoubleArrayElements(JNIEnv* env,
2007 jdoubleArray array, jdouble* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002008 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002009 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002010}
2011
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002012void GetBooleanArrayRegion(JNIEnv* env,
2013 jbooleanArray array, jsize start, jsize l, jboolean* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002014 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002015 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002016}
2017
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002018void GetByteArrayRegion(JNIEnv* env,
2019 jbyteArray array, jsize start, jsize len, jbyte* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002020 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002021 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002022}
2023
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002024void GetCharArrayRegion(JNIEnv* env,
2025 jcharArray array, jsize start, jsize len, jchar* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002026 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002027 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002028}
2029
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002030void GetShortArrayRegion(JNIEnv* env,
2031 jshortArray array, jsize start, jsize len, jshort* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002032 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002033 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002034}
2035
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002036void GetIntArrayRegion(JNIEnv* env,
2037 jintArray array, jsize start, jsize len, jint* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002038 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002039 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002040}
2041
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002042void GetLongArrayRegion(JNIEnv* env,
2043 jlongArray array, jsize start, jsize len, jlong* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002044 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002045 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002046}
2047
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002048void GetFloatArrayRegion(JNIEnv* env,
2049 jfloatArray array, jsize start, jsize len, jfloat* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002050 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002051 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002052}
2053
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002054void GetDoubleArrayRegion(JNIEnv* env,
2055 jdoubleArray array, jsize start, jsize len, jdouble* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002056 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002057 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002058}
2059
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002060void SetBooleanArrayRegion(JNIEnv* env,
2061 jbooleanArray array, jsize start, jsize l, const jboolean* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002062 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002063 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002064}
2065
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002066void SetByteArrayRegion(JNIEnv* env,
2067 jbyteArray array, jsize start, jsize len, const jbyte* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002068 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002069 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002070}
2071
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002072void SetCharArrayRegion(JNIEnv* env,
2073 jcharArray array, jsize start, jsize len, const jchar* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002074 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002075 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002076}
2077
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002078void SetShortArrayRegion(JNIEnv* env,
2079 jshortArray array, jsize start, jsize len, const jshort* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002080 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002081 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002082}
2083
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002084void SetIntArrayRegion(JNIEnv* env,
2085 jintArray array, jsize start, jsize len, const jint* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002086 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002087 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002088}
2089
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002090void SetLongArrayRegion(JNIEnv* env,
2091 jlongArray array, jsize start, jsize len, const jlong* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002092 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002093 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002094}
2095
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002096void SetFloatArrayRegion(JNIEnv* env,
2097 jfloatArray array, jsize start, jsize len, const jfloat* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002098 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002099 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002100}
2101
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002102void SetDoubleArrayRegion(JNIEnv* env,
2103 jdoubleArray array, jsize start, jsize len, const jdouble* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002104 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002105 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002106}
2107
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002108jint RegisterNatives(JNIEnv* env,
2109 jclass clazz, const JNINativeMethod* methods, jint nMethods) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002110 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07002111 Class* klass = Decode<Class*>(ts, clazz);
Ian Rogers4dd71f12011-08-16 14:16:02 -07002112 for(int i = 0; i < nMethods; i++) {
2113 const char* name = methods[i].name;
2114 const char* sig = methods[i].signature;
Elliott Hughes0af55432011-08-17 18:37:28 -07002115
2116 if (*sig == '!') {
2117 // TODO: fast jni. it's too noisy to log all these.
2118 ++sig;
2119 }
2120
Ian Rogers4dd71f12011-08-16 14:16:02 -07002121 Method* method = klass->FindDirectMethod(name, sig);
2122 if (method == NULL) {
2123 method = klass->FindVirtualMethod(name, sig);
2124 }
2125 if (method == NULL) {
2126 Thread* self = Thread::Current();
2127 std::string class_name = klass->GetDescriptor().ToString();
2128 // TODO: pretty print method names through a single routine
2129 self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
2130 "no method \"%s.%s%s\"",
2131 class_name.c_str(), name, sig);
2132 return JNI_ERR;
2133 } else if (!method->IsNative()) {
2134 Thread* self = Thread::Current();
2135 std::string class_name = klass->GetDescriptor().ToString();
2136 // TODO: pretty print method names through a single routine
2137 self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
2138 "method \"%s.%s%s\" is not native",
2139 class_name.c_str(), name, sig);
2140 return JNI_ERR;
2141 }
2142 method->RegisterNative(methods[i].fnPtr);
2143 }
2144 return JNI_OK;
Carl Shapiroea4dca82011-08-01 13:45:38 -07002145}
2146
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002147jint UnregisterNatives(JNIEnv* env, jclass clazz) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002148 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002149 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002150 return 0;
2151}
2152
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002153jint MonitorEnter(JNIEnv* env, jobject obj) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002154 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002155 UNIMPLEMENTED(WARNING);
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002156 return 0;
2157}
2158
2159jint MonitorExit(JNIEnv* env, jobject obj) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002160 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002161 UNIMPLEMENTED(WARNING);
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002162 return 0;
2163}
2164
Elliott Hughesb20a5542011-08-12 18:03:12 -07002165jint GetJavaVM(JNIEnv* env, JavaVM** vm) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002166 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07002167 Runtime* runtime = Runtime::Current();
2168 if (runtime != NULL) {
Elliott Hughes0af55432011-08-17 18:37:28 -07002169 *vm = reinterpret_cast<JavaVM*>(runtime->GetJavaVM());
Elliott Hughesf2682d52011-08-15 16:37:04 -07002170 } else {
2171 *vm = NULL;
2172 }
2173 return (*vm != NULL) ? JNI_OK : JNI_ERR;
Carl Shapiroea4dca82011-08-01 13:45:38 -07002174}
2175
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002176void GetStringRegion(JNIEnv* env,
2177 jstring str, jsize start, jsize len, jchar* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002178 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002179 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002180}
2181
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002182void GetStringUTFRegion(JNIEnv* env,
2183 jstring str, jsize start, jsize len, char* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002184 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002185 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002186}
2187
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002188void* GetPrimitiveArrayCritical(JNIEnv* env,
2189 jarray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002190 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002191 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002192 return NULL;
2193}
2194
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002195void ReleasePrimitiveArrayCritical(JNIEnv* env,
2196 jarray array, void* carray, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002197 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002198 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002199}
2200
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002201const jchar* GetStringCritical(JNIEnv* env, jstring s, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002202 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002203 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002204 return NULL;
2205}
2206
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002207void ReleaseStringCritical(JNIEnv* env, jstring s, const jchar* cstr) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002208 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002209 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002210}
2211
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002212jboolean ExceptionCheck(JNIEnv* env) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002213 ScopedJniThreadState ts(env);
Elliott Hughesb20a5542011-08-12 18:03:12 -07002214 return ts.Self()->IsExceptionPending() ? JNI_TRUE : JNI_FALSE;
Carl Shapiroea4dca82011-08-01 13:45:38 -07002215}
2216
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002217jobject NewDirectByteBuffer(JNIEnv* env, void* address, jlong capacity) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002218 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002219 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002220 return NULL;
2221}
2222
2223
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002224void* GetDirectBufferAddress(JNIEnv* env, jobject buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002225 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002226 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002227 return NULL;
2228}
2229
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002230jlong GetDirectBufferCapacity(JNIEnv* env, jobject buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002231 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002232 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002233 return 0;
2234}
2235
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002236jobjectRefType GetObjectRefType(JNIEnv* env, jobject jobj) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002237 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002238 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002239 return JNIInvalidRefType;
2240}
2241
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002242static const struct JNINativeInterface gNativeInterface = {
Carl Shapiroea4dca82011-08-01 13:45:38 -07002243 NULL, // reserved0.
2244 NULL, // reserved1.
2245 NULL, // reserved2.
2246 NULL, // reserved3.
2247 GetVersion,
2248 DefineClass,
2249 FindClass,
2250 FromReflectedMethod,
2251 FromReflectedField,
2252 ToReflectedMethod,
2253 GetSuperclass,
2254 IsAssignableFrom,
2255 ToReflectedField,
2256 Throw,
2257 ThrowNew,
2258 ExceptionOccurred,
2259 ExceptionDescribe,
2260 ExceptionClear,
2261 FatalError,
2262 PushLocalFrame,
2263 PopLocalFrame,
2264 NewGlobalRef,
2265 DeleteGlobalRef,
2266 DeleteLocalRef,
2267 IsSameObject,
2268 NewLocalRef,
2269 EnsureLocalCapacity,
2270 AllocObject,
2271 NewObject,
2272 NewObjectV,
2273 NewObjectA,
2274 GetObjectClass,
2275 IsInstanceOf,
2276 GetMethodID,
2277 CallObjectMethod,
2278 CallObjectMethodV,
2279 CallObjectMethodA,
2280 CallBooleanMethod,
2281 CallBooleanMethodV,
2282 CallBooleanMethodA,
2283 CallByteMethod,
2284 CallByteMethodV,
2285 CallByteMethodA,
2286 CallCharMethod,
2287 CallCharMethodV,
2288 CallCharMethodA,
2289 CallShortMethod,
2290 CallShortMethodV,
2291 CallShortMethodA,
2292 CallIntMethod,
2293 CallIntMethodV,
2294 CallIntMethodA,
2295 CallLongMethod,
2296 CallLongMethodV,
2297 CallLongMethodA,
2298 CallFloatMethod,
2299 CallFloatMethodV,
2300 CallFloatMethodA,
2301 CallDoubleMethod,
2302 CallDoubleMethodV,
2303 CallDoubleMethodA,
2304 CallVoidMethod,
2305 CallVoidMethodV,
2306 CallVoidMethodA,
2307 CallNonvirtualObjectMethod,
2308 CallNonvirtualObjectMethodV,
2309 CallNonvirtualObjectMethodA,
2310 CallNonvirtualBooleanMethod,
2311 CallNonvirtualBooleanMethodV,
2312 CallNonvirtualBooleanMethodA,
2313 CallNonvirtualByteMethod,
2314 CallNonvirtualByteMethodV,
2315 CallNonvirtualByteMethodA,
2316 CallNonvirtualCharMethod,
2317 CallNonvirtualCharMethodV,
2318 CallNonvirtualCharMethodA,
2319 CallNonvirtualShortMethod,
2320 CallNonvirtualShortMethodV,
2321 CallNonvirtualShortMethodA,
2322 CallNonvirtualIntMethod,
2323 CallNonvirtualIntMethodV,
2324 CallNonvirtualIntMethodA,
2325 CallNonvirtualLongMethod,
2326 CallNonvirtualLongMethodV,
2327 CallNonvirtualLongMethodA,
2328 CallNonvirtualFloatMethod,
2329 CallNonvirtualFloatMethodV,
2330 CallNonvirtualFloatMethodA,
2331 CallNonvirtualDoubleMethod,
2332 CallNonvirtualDoubleMethodV,
2333 CallNonvirtualDoubleMethodA,
2334 CallNonvirtualVoidMethod,
2335 CallNonvirtualVoidMethodV,
2336 CallNonvirtualVoidMethodA,
2337 GetFieldID,
2338 GetObjectField,
2339 GetBooleanField,
2340 GetByteField,
2341 GetCharField,
2342 GetShortField,
2343 GetIntField,
2344 GetLongField,
2345 GetFloatField,
2346 GetDoubleField,
2347 SetObjectField,
2348 SetBooleanField,
2349 SetByteField,
2350 SetCharField,
2351 SetShortField,
2352 SetIntField,
2353 SetLongField,
2354 SetFloatField,
2355 SetDoubleField,
2356 GetStaticMethodID,
2357 CallStaticObjectMethod,
2358 CallStaticObjectMethodV,
2359 CallStaticObjectMethodA,
2360 CallStaticBooleanMethod,
2361 CallStaticBooleanMethodV,
2362 CallStaticBooleanMethodA,
2363 CallStaticByteMethod,
2364 CallStaticByteMethodV,
2365 CallStaticByteMethodA,
2366 CallStaticCharMethod,
2367 CallStaticCharMethodV,
2368 CallStaticCharMethodA,
2369 CallStaticShortMethod,
2370 CallStaticShortMethodV,
2371 CallStaticShortMethodA,
2372 CallStaticIntMethod,
2373 CallStaticIntMethodV,
2374 CallStaticIntMethodA,
2375 CallStaticLongMethod,
2376 CallStaticLongMethodV,
2377 CallStaticLongMethodA,
2378 CallStaticFloatMethod,
2379 CallStaticFloatMethodV,
2380 CallStaticFloatMethodA,
2381 CallStaticDoubleMethod,
2382 CallStaticDoubleMethodV,
2383 CallStaticDoubleMethodA,
2384 CallStaticVoidMethod,
2385 CallStaticVoidMethodV,
2386 CallStaticVoidMethodA,
2387 GetStaticFieldID,
2388 GetStaticObjectField,
2389 GetStaticBooleanField,
2390 GetStaticByteField,
2391 GetStaticCharField,
2392 GetStaticShortField,
2393 GetStaticIntField,
2394 GetStaticLongField,
2395 GetStaticFloatField,
2396 GetStaticDoubleField,
2397 SetStaticObjectField,
2398 SetStaticBooleanField,
2399 SetStaticByteField,
2400 SetStaticCharField,
2401 SetStaticShortField,
2402 SetStaticIntField,
2403 SetStaticLongField,
2404 SetStaticFloatField,
2405 SetStaticDoubleField,
2406 NewString,
2407 GetStringLength,
2408 GetStringChars,
2409 ReleaseStringChars,
2410 NewStringUTF,
2411 GetStringUTFLength,
2412 GetStringUTFChars,
2413 ReleaseStringUTFChars,
2414 GetArrayLength,
2415 NewObjectArray,
2416 GetObjectArrayElement,
2417 SetObjectArrayElement,
2418 NewBooleanArray,
2419 NewByteArray,
2420 NewCharArray,
2421 NewShortArray,
2422 NewIntArray,
2423 NewLongArray,
2424 NewFloatArray,
2425 NewDoubleArray,
2426 GetBooleanArrayElements,
2427 GetByteArrayElements,
2428 GetCharArrayElements,
2429 GetShortArrayElements,
2430 GetIntArrayElements,
2431 GetLongArrayElements,
2432 GetFloatArrayElements,
2433 GetDoubleArrayElements,
2434 ReleaseBooleanArrayElements,
2435 ReleaseByteArrayElements,
2436 ReleaseCharArrayElements,
2437 ReleaseShortArrayElements,
2438 ReleaseIntArrayElements,
2439 ReleaseLongArrayElements,
2440 ReleaseFloatArrayElements,
2441 ReleaseDoubleArrayElements,
2442 GetBooleanArrayRegion,
2443 GetByteArrayRegion,
2444 GetCharArrayRegion,
2445 GetShortArrayRegion,
2446 GetIntArrayRegion,
2447 GetLongArrayRegion,
2448 GetFloatArrayRegion,
2449 GetDoubleArrayRegion,
2450 SetBooleanArrayRegion,
2451 SetByteArrayRegion,
2452 SetCharArrayRegion,
2453 SetShortArrayRegion,
2454 SetIntArrayRegion,
2455 SetLongArrayRegion,
2456 SetFloatArrayRegion,
2457 SetDoubleArrayRegion,
2458 RegisterNatives,
2459 UnregisterNatives,
2460 MonitorEnter,
2461 MonitorExit,
2462 GetJavaVM,
2463 GetStringRegion,
2464 GetStringUTFRegion,
2465 GetPrimitiveArrayCritical,
2466 ReleasePrimitiveArrayCritical,
2467 GetStringCritical,
2468 ReleaseStringCritical,
2469 NewWeakGlobalRef,
2470 DeleteWeakGlobalRef,
2471 ExceptionCheck,
2472 NewDirectByteBuffer,
2473 GetDirectBufferAddress,
2474 GetDirectBufferCapacity,
2475 GetObjectRefType,
2476};
2477
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002478static const size_t kMonitorsInitial = 32; // Arbitrary.
2479static const size_t kMonitorsMax = 4096; // Arbitrary sanity check.
2480
2481static const size_t kLocalsInitial = 64; // Arbitrary.
2482static const size_t kLocalsMax = 512; // Arbitrary sanity check.
Elliott Hughesbbd76712011-08-17 10:25:24 -07002483
Elliott Hughes515a5bc2011-08-17 11:08:34 -07002484JNIEnvExt::JNIEnvExt(Thread* self, bool check_jni)
Elliott Hughesbbd76712011-08-17 10:25:24 -07002485 : fns(&gNativeInterface),
2486 self(self),
Elliott Hughes515a5bc2011-08-17 11:08:34 -07002487 check_jni(check_jni),
Elliott Hughesbbd76712011-08-17 10:25:24 -07002488 critical(false),
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002489 monitors("monitors", kMonitorsInitial, kMonitorsMax),
2490 locals(kLocalsInitial, kLocalsMax, kLocal) {
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002491}
2492
Carl Shapiroea4dca82011-08-01 13:45:38 -07002493// JNI Invocation interface.
2494
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002495extern "C" jint JNI_CreateJavaVM(JavaVM** p_vm, void** p_env, void* vm_args) {
2496 const JavaVMInitArgs* args = static_cast<JavaVMInitArgs*>(vm_args);
2497 if (args->version < JNI_VERSION_1_2) {
2498 return JNI_EVERSION;
2499 }
2500 Runtime::Options options;
2501 for (int i = 0; i < args->nOptions; ++i) {
2502 JavaVMOption* option = &args->options[i];
Carl Shapirofc322c72011-07-27 00:20:01 -07002503 options.push_back(std::make_pair(StringPiece(option->optionString),
2504 option->extraInfo));
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002505 }
2506 bool ignore_unrecognized = args->ignoreUnrecognized;
Elliott Hughesf2682d52011-08-15 16:37:04 -07002507 Runtime* runtime = Runtime::Create(options, ignore_unrecognized);
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002508 if (runtime == NULL) {
2509 return JNI_ERR;
2510 } else {
2511 *p_env = reinterpret_cast<JNIEnv*>(Thread::Current()->GetJniEnv());
Elliott Hughes0af55432011-08-17 18:37:28 -07002512 *p_vm = reinterpret_cast<JavaVM*>(runtime->GetJavaVM());
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002513 return JNI_OK;
2514 }
2515}
2516
Elliott Hughesf2682d52011-08-15 16:37:04 -07002517extern "C" jint JNI_GetCreatedJavaVMs(JavaVM** vms, jsize, jsize* vm_count) {
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002518 Runtime* runtime = Runtime::Current();
2519 if (runtime == NULL) {
Elliott Hughesf2682d52011-08-15 16:37:04 -07002520 *vm_count = 0;
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002521 } else {
Elliott Hughesf2682d52011-08-15 16:37:04 -07002522 *vm_count = 1;
Elliott Hughes0af55432011-08-17 18:37:28 -07002523 vms[0] = reinterpret_cast<JavaVM*>(runtime->GetJavaVM());
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002524 }
2525 return JNI_OK;
2526}
2527
2528// Historically unsupported.
2529extern "C" jint JNI_GetDefaultJavaVMInitArgs(void* vm_args) {
2530 return JNI_ERR;
2531}
2532
Elliott Hughesf2682d52011-08-15 16:37:04 -07002533jint DestroyJavaVM(JavaVM* vm) {
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002534 if (vm == NULL) {
2535 return JNI_ERR;
2536 } else {
Elliott Hughesf2682d52011-08-15 16:37:04 -07002537 JavaVMExt* raw_vm = reinterpret_cast<JavaVMExt*>(vm);
2538 delete raw_vm->runtime;
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002539 return JNI_OK;
2540 }
2541}
2542
Elliott Hughesf2682d52011-08-15 16:37:04 -07002543jint AttachCurrentThread(JavaVM* vm, JNIEnv** p_env, void* thr_args) {
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002544 if (vm == NULL || p_env == NULL) {
2545 return JNI_ERR;
2546 }
Elliott Hughesf2682d52011-08-15 16:37:04 -07002547 JavaVMExt* raw_vm = reinterpret_cast<JavaVMExt*>(vm);
2548 Runtime* runtime = raw_vm->runtime;
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002549 const char* name = NULL;
2550 if (thr_args != NULL) {
2551 // TODO: check version
2552 name = static_cast<JavaVMAttachArgs*>(thr_args)->name;
2553 // TODO: thread group
2554 }
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002555 bool success = runtime->AttachCurrentThread(name, p_env);
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002556 if (!success) {
2557 return JNI_ERR;
2558 } else {
2559 return JNI_OK;
2560 }
2561}
2562
Elliott Hughesf2682d52011-08-15 16:37:04 -07002563jint DetachCurrentThread(JavaVM* vm) {
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002564 if (vm == NULL) {
2565 return JNI_ERR;
2566 } else {
Elliott Hughesf2682d52011-08-15 16:37:04 -07002567 JavaVMExt* raw_vm = reinterpret_cast<JavaVMExt*>(vm);
2568 Runtime* runtime = raw_vm->runtime;
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002569 runtime->DetachCurrentThread();
2570 return JNI_OK;
2571 }
2572}
2573
Elliott Hughesf2682d52011-08-15 16:37:04 -07002574jint GetEnv(JavaVM* vm, void** env, jint version) {
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002575 if (version < JNI_VERSION_1_1 || version > JNI_VERSION_1_6) {
2576 return JNI_EVERSION;
2577 }
2578 if (vm == NULL || env == NULL) {
2579 return JNI_ERR;
2580 }
2581 Thread* thread = Thread::Current();
2582 if (thread == NULL) {
2583 *env = NULL;
2584 return JNI_EDETACHED;
2585 }
2586 *env = thread->GetJniEnv();
2587 return JNI_OK;
2588}
2589
Elliott Hughesf2682d52011-08-15 16:37:04 -07002590jint AttachCurrentThreadAsDaemon(JavaVM* vm, JNIEnv** p_env, void* thr_args) {
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002591 if (vm == NULL || p_env == NULL) {
2592 return JNI_ERR;
2593 }
Elliott Hughesf2682d52011-08-15 16:37:04 -07002594 JavaVMExt* raw_vm = reinterpret_cast<JavaVMExt*>(vm);
2595 Runtime* runtime = raw_vm->runtime;
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002596 const char* name = NULL;
2597 if (thr_args != NULL) {
2598 // TODO: check version
2599 name = static_cast<JavaVMAttachArgs*>(thr_args)->name;
2600 // TODO: thread group
2601 }
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002602 bool success = runtime->AttachCurrentThreadAsDaemon(name, p_env);
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002603 if (!success) {
2604 return JNI_ERR;
2605 } else {
2606 return JNI_OK;
2607 }
2608}
2609
Elliott Hughesf2682d52011-08-15 16:37:04 -07002610struct JNIInvokeInterface gInvokeInterface = {
Carl Shapiroea4dca82011-08-01 13:45:38 -07002611 NULL, // reserved0
2612 NULL, // reserved1
2613 NULL, // reserved2
2614 DestroyJavaVM,
2615 AttachCurrentThread,
2616 DetachCurrentThread,
2617 GetEnv,
2618 AttachCurrentThreadAsDaemon
2619};
2620
Elliott Hughesbbd76712011-08-17 10:25:24 -07002621static const size_t kPinTableInitialSize = 16;
2622static const size_t kPinTableMaxSize = 1024;
2623
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002624static const size_t kGlobalsInitial = 512; // Arbitrary.
2625static const size_t kGlobalsMax = 51200; // Arbitrary sanity check.
2626
2627static const size_t kWeakGlobalsInitial = 16; // Arbitrary.
2628static const size_t kWeakGlobalsMax = 51200; // Arbitrary sanity check.
2629
Elliott Hughes0af55432011-08-17 18:37:28 -07002630JavaVMExt::JavaVMExt(Runtime* runtime, bool check_jni, bool verbose_jni)
Elliott Hughesbbd76712011-08-17 10:25:24 -07002631 : fns(&gInvokeInterface),
2632 runtime(runtime),
Elliott Hughes515a5bc2011-08-17 11:08:34 -07002633 check_jni(check_jni),
Elliott Hughes0af55432011-08-17 18:37:28 -07002634 verbose_jni(verbose_jni),
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002635 pin_table("pin table", kPinTableInitialSize, kPinTableMaxSize),
Elliott Hughes18c07532011-08-18 15:50:51 -07002636 globals_lock(Mutex::Create("JNI global reference table lock")),
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002637 globals(kGlobalsInitial, kGlobalsMax, kGlobal),
Elliott Hughes18c07532011-08-18 15:50:51 -07002638 weak_globals_lock(Mutex::Create("JNI weak global reference table lock")),
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002639 weak_globals(kWeakGlobalsInitial, kWeakGlobalsMax, kWeakGlobal) {
Elliott Hughesf2682d52011-08-15 16:37:04 -07002640}
2641
Elliott Hughesde69d7f2011-08-18 16:49:37 -07002642JavaVMExt::~JavaVMExt() {
2643 delete globals_lock;
2644 delete weak_globals_lock;
2645}
2646
Ian Rogersdf20fe02011-07-20 20:34:16 -07002647} // namespace art