blob: 599b0fe68f6fcb997ff23193ea5dade88dd0b41e [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 Hughes40ef99e2011-08-11 17:44:34 -070011#include "class_linker.h"
Carl Shapiroea4dca82011-08-01 13:45:38 -070012#include "jni.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070013#include "logging.h"
Carl Shapiro9b9ba282011-08-14 15:30:39 -070014#include "object.h"
Carl Shapiro2ed144c2011-07-26 16:52:08 -070015#include "runtime.h"
Carl Shapirofc322c72011-07-27 00:20:01 -070016#include "scoped_ptr.h"
17#include "stringpiece.h"
Carl Shapiro2ed144c2011-07-26 16:52:08 -070018#include "thread.h"
Ian Rogersdf20fe02011-07-20 20:34:16 -070019
20namespace art {
21
Elliott Hughes0af55432011-08-17 18:37:28 -070022enum JNI_OnLoadState {
23 kPending = 0, /* initial state, must be zero */
24 kFailed,
25 kOkay,
26};
27
28struct SharedLibrary {
29 SharedLibrary() : jni_on_load_lock("JNI_OnLoad") {
30 }
31
32 // Path to library "/system/lib/libjni.so".
33 std::string path;
34
35 // The void* returned by dlopen(3).
36 void* handle;
37
38 // The ClassLoader this library is associated with.
39 Object* class_loader;
40
41 // Guards remaining items.
42 Mutex jni_on_load_lock;
43 // Wait for JNI_OnLoad in other thread.
44 pthread_cond_t jni_on_load_cond;
45 // Recursive invocation guard.
46 uint32_t jni_on_load_tid;
47 // Result of earlier JNI_OnLoad call.
48 JNI_OnLoadState jni_on_load_result;
49};
50
51/*
52 * Check the result of an earlier call to JNI_OnLoad on this library. If
53 * the call has not yet finished in another thread, wait for it.
54 */
55bool CheckOnLoadResult(JavaVMExt* vm, SharedLibrary* library) {
56 Thread* self = Thread::Current();
57 if (library->jni_on_load_tid == self->GetId()) {
58 // Check this so we don't end up waiting for ourselves. We need
59 // to return "true" so the caller can continue.
60 LOG(INFO) << *self << " recursive attempt to load library "
61 << "\"" << library->path << "\"";
62 return true;
63 }
64
65 UNIMPLEMENTED(ERROR) << "need to pthread_cond_wait!";
66 // MutexLock mu(&library->jni_on_load_lock);
67 while (library->jni_on_load_result == kPending) {
68 if (vm->verbose_jni) {
69 LOG(INFO) << "[" << *self << " waiting for \"" << library->path << "\" "
70 << "JNI_OnLoad...]";
71 }
72 Thread::State old_state = self->GetState();
73 self->SetState(Thread::kWaiting); // TODO: VMWAIT
74 // pthread_cond_wait(&library->jni_on_load_cond, &library->jni_on_load_lock);
75 self->SetState(old_state);
76 }
77
78 bool okay = (library->jni_on_load_result == kOkay);
79 if (vm->verbose_jni) {
80 LOG(INFO) << "[Earlier JNI_OnLoad for \"" << library->path << "\" "
81 << (okay ? "succeeded" : "failed") << "]";
82 }
83 return okay;
84}
85
86typedef int (*JNI_OnLoadFn)(JavaVM*, void*);
87
88/*
89 * Load native code from the specified absolute pathname. Per the spec,
90 * if we've already loaded a library with the specified pathname, we
91 * return without doing anything.
92 *
93 * TODO? for better results we should absolutify the pathname. For fully
94 * correct results we should stat to get the inode and compare that. The
95 * existing implementation is fine so long as everybody is using
96 * System.loadLibrary.
97 *
98 * The library will be associated with the specified class loader. The JNI
99 * spec says we can't load the same library into more than one class loader.
100 *
101 * Returns "true" on success. On failure, sets *detail to a
102 * human-readable description of the error or NULL if no detail is
103 * available; ownership of the string is transferred to the caller.
104 */
105bool JavaVMExt::LoadNativeLibrary(const std::string& path, Object* class_loader, char** detail) {
106 *detail = NULL;
107
108 // See if we've already loaded this library. If we have, and the class loader
109 // matches, return successfully without doing anything.
110 SharedLibrary* library = libraries[path];
111 if (library != NULL) {
112 if (library->class_loader != class_loader) {
113 LOG(WARNING) << "Shared library \"" << path << "\" already opened by "
114 << "ClassLoader " << library->class_loader << "; "
115 << "can't open in " << class_loader;
116 *detail = strdup("already opened by different ClassLoader");
117 return false;
118 }
119 if (verbose_jni) {
120 LOG(INFO) << "[Shared library \"" << path << "\" already loaded in "
121 << "ClassLoader " << class_loader << "]";
122 }
123 if (!CheckOnLoadResult(this, library)) {
124 *detail = strdup("JNI_OnLoad failed before");
125 return false;
126 }
127 return true;
128 }
129
130 // Open the shared library. Because we're using a full path, the system
131 // doesn't have to search through LD_LIBRARY_PATH. (It may do so to
132 // resolve this library's dependencies though.)
133
134 // Failures here are expected when java.library.path has several entries
135 // and we have to hunt for the lib.
136
137 // The current version of the dynamic linker prints detailed information
138 // about dlopen() failures. Some things to check if the message is
139 // cryptic:
140 // - make sure the library exists on the device
141 // - verify that the right path is being opened (the debug log message
142 // above can help with that)
143 // - check to see if the library is valid (e.g. not zero bytes long)
144 // - check config/prelink-linux-arm.map to ensure that the library
145 // is listed and is not being overrun by the previous entry (if
146 // loading suddenly stops working on a prelinked library, this is
147 // a good one to check)
148 // - write a trivial app that calls sleep() then dlopen(), attach
149 // to it with "strace -p <pid>" while it sleeps, and watch for
150 // attempts to open nonexistent dependent shared libs
151
152 // TODO: automate some of these checks!
153
Elliott Hughes0af55432011-08-17 18:37:28 -0700154 // This can execute slowly for a large library on a busy system, so we
155 // want to switch from RUNNING to VMWAIT while it executes. This allows
156 // the GC to ignore us.
157 Thread* self = Thread::Current();
158 Thread::State old_state = self->GetState();
159 self->SetState(Thread::kWaiting); // TODO: VMWAIT
160 void* handle = dlopen(path.c_str(), RTLD_LAZY);
161 self->SetState(old_state);
162
163 if (verbose_jni) {
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700164 LOG(INFO) << "[Call to dlopen(\"" << path << "\") returned " << handle << "]";
Elliott Hughes0af55432011-08-17 18:37:28 -0700165 }
166
167 if (handle == NULL) {
168 *detail = strdup(dlerror());
169 return false;
170 }
171
172 // Create a new entry.
173 library = new SharedLibrary;
174 library->path = path;
175 library->handle = handle;
176 library->class_loader = class_loader;
177 UNIMPLEMENTED(ERROR) << "missing pthread_cond_init";
178 // pthread_cond_init(&library->onLoadCond, NULL);
179 library->jni_on_load_tid = self->GetId();
180
181 libraries[path] = library;
182
183// if (pNewEntry != pActualEntry) {
184// LOG(INFO) << "WOW: we lost a race to add a shared library (\"" << path << "\" ClassLoader=" << class_loader <<")";
185// freeSharedLibEntry(pNewEntry);
186// return CheckOnLoadResult(this, pActualEntry);
187// } else
188 {
189 if (verbose_jni) {
190 LOG(INFO) << "[Added shared library \"" << path << "\" for ClassLoader " << class_loader << "]";
191 }
192
193 bool result = true;
194 void* sym = dlsym(handle, "JNI_OnLoad");
195 if (sym == NULL) {
196 if (verbose_jni) {
197 LOG(INFO) << "[No JNI_OnLoad found in \"" << path << "\"]";
198 }
199 } else {
200 // Call JNI_OnLoad. We have to override the current class
201 // loader, which will always be "null" since the stuff at the
202 // top of the stack is around Runtime.loadLibrary(). (See
203 // the comments in the JNI FindClass function.)
204 UNIMPLEMENTED(WARNING) << "need to override current class loader";
205 JNI_OnLoadFn jni_on_load = reinterpret_cast<JNI_OnLoadFn>(sym);
206 //Object* prevOverride = self->classLoaderOverride;
207 //self->classLoaderOverride = classLoader;
208
209 old_state = self->GetState();
210 self->SetState(Thread::kNative);
211 if (verbose_jni) {
212 LOG(INFO) << "[Calling JNI_OnLoad in \"" << path << "\"]";
213 }
214 int version = (*jni_on_load)(reinterpret_cast<JavaVM*>(this), NULL);
215 self->SetState(old_state);
216
217 UNIMPLEMENTED(WARNING) << "need to restore current class loader";
218 //self->classLoaderOverride = prevOverride;
219
220 if (version != JNI_VERSION_1_2 &&
221 version != JNI_VERSION_1_4 &&
222 version != JNI_VERSION_1_6) {
223 LOG(WARNING) << "JNI_OnLoad in \"" << path << "\" returned "
224 << "bad version: " << version;
225 // It's unwise to call dlclose() here, but we can mark it
226 // as bad and ensure that future load attempts will fail.
227 // We don't know how far JNI_OnLoad got, so there could
228 // be some partially-initialized stuff accessible through
229 // newly-registered native method calls. We could try to
230 // unregister them, but that doesn't seem worthwhile.
231 result = false;
232 } else {
233 if (verbose_jni) {
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700234 LOG(INFO) << "[Returned " << (result ? "successfully" : "failure")
235 << " from JNI_OnLoad in \"" << path << "\"]";
Elliott Hughes0af55432011-08-17 18:37:28 -0700236 }
237 }
238 }
239
240 library->jni_on_load_result = result ? kOkay : kFailed;
241 library->jni_on_load_tid = 0;
242
243 // Broadcast a wakeup to anybody sleeping on the condition variable.
244 UNIMPLEMENTED(ERROR) << "missing pthread_cond_broadcast";
245 // MutexLock mu(&library->jni_on_load_lock);
246 // pthread_cond_broadcast(&library->jni_on_load_cond);
247 return result;
248 }
249}
250
Elliott Hughes22f40932011-08-12 13:06:37 -0700251// Entry/exit processing for all JNI calls.
252//
253// This performs the necessary thread state switching, lets us amortize the
254// cost of working out the current thread, and lets us check (and repair) apps
255// that are using a JNIEnv on the wrong thread.
256class ScopedJniThreadState {
257 public:
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700258 explicit ScopedJniThreadState(JNIEnv* env)
259 : env_(reinterpret_cast<JNIEnvExt*>(env)) {
Elliott Hughesb20a5542011-08-12 18:03:12 -0700260 self_ = ThreadForEnv(env);
Elliott Hughes22f40932011-08-12 13:06:37 -0700261 self_->SetState(Thread::kRunnable);
262 }
263
264 ~ScopedJniThreadState() {
265 self_->SetState(Thread::kNative);
266 }
267
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700268 JNIEnvExt* Env() {
269 return env_;
270 }
271
Elliott Hughesb20a5542011-08-12 18:03:12 -0700272 Thread* Self() {
Elliott Hughes22f40932011-08-12 13:06:37 -0700273 return self_;
274 }
275
Elliott Hughesb20a5542011-08-12 18:03:12 -0700276 private:
277 static Thread* ThreadForEnv(JNIEnv* env) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700278 // TODO: need replacement for gDvmJni.
279 bool workAroundAppJniBugs = true;
280 Thread* env_self = reinterpret_cast<JNIEnvExt*>(env)->self;
281 Thread* self = workAroundAppJniBugs ? Thread::Current() : env_self;
282 if (self != env_self) {
Elliott Hughes330304d2011-08-12 14:28:05 -0700283 LOG(ERROR) << "JNI ERROR: JNIEnv for " << *env_self
284 << " used on " << *self;
285 // TODO: dump stack
Elliott Hughes22f40932011-08-12 13:06:37 -0700286 }
287 return self;
288 }
289
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700290 JNIEnvExt* env_;
Elliott Hughes22f40932011-08-12 13:06:37 -0700291 Thread* self_;
292 DISALLOW_COPY_AND_ASSIGN(ScopedJniThreadState);
293};
294
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700295/*
296 * Add a local reference for an object to the current stack frame. When
297 * the native function returns, the reference will be discarded.
298 *
299 * We need to allow the same reference to be added multiple times.
300 *
301 * This will be called on otherwise unreferenced objects. We cannot do
302 * GC allocations here, and it's best if we don't grab a mutex.
303 *
304 * Returns the local reference (currently just the same pointer that was
305 * passed in), or NULL on failure.
306 */
Elliott Hughes8a26c5c2011-08-15 18:35:43 -0700307template<typename T>
308T AddLocalReference(ScopedJniThreadState& ts, Object* obj) {
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700309 if (obj == NULL) {
310 return NULL;
311 }
312
313 IndirectReferenceTable& locals = ts.Env()->locals;
314
315 uint32_t cookie = IRT_FIRST_SEGMENT; // TODO
316 IndirectRef ref = locals.Add(cookie, obj);
317 if (ref == NULL) {
318 // TODO: just change Add's DCHECK to CHECK and lose this?
319 locals.Dump();
320 LOG(FATAL) << "Failed adding to JNI local reference table "
321 << "(has " << locals.Capacity() << " entries)";
322 // TODO: dvmDumpThread(dvmThreadSelf(), false);
323 }
324
325#if 0 // TODO: fix this to understand PushLocalFrame, so we can turn it on.
326 if (ts.Env()->check_jni) {
327 size_t entry_count = locals.Capacity();
328 if (entry_count > 16) {
329 std::string class_name(PrettyDescriptor(obj->GetClass()->GetDescriptor()));
330 LOG(WARNING) << "Warning: more than 16 JNI local references: "
331 << entry_count << " (most recent was a " << class_name << ")";
332 locals.Dump();
333 // TODO: dvmDumpThread(dvmThreadSelf(), false);
334 // dvmAbort();
335 }
336 }
337#endif
338
339 if (false /*gDvmJni.workAroundAppJniBugs*/) { // TODO
340 // Hand out direct pointers to support broken old apps.
341 return reinterpret_cast<T>(obj);
342 }
343
344 return reinterpret_cast<T>(ref);
345}
346
347template<typename T>
348T Decode(ScopedJniThreadState& ts, jobject obj) {
349 if (obj == NULL) {
350 return NULL;
351 }
352
353 IndirectRef ref = reinterpret_cast<IndirectRef>(obj);
354 IndirectRefKind kind = GetIndirectRefKind(ref);
355 Object* result;
356 switch (kind) {
357 case kLocal:
358 {
359 IndirectReferenceTable& locals = ts.Env()->locals;
360 result = locals.Get(ref);
361 break;
362 }
363 case kGlobal:
364 {
365 JavaVMExt* vm = Runtime::Current()->GetJavaVM();
366 IndirectReferenceTable& globals = vm->globals;
367 MutexLock mu(&vm->globals_lock);
368 result = globals.Get(ref);
369 break;
370 }
371 case kWeakGlobal:
372 {
373 JavaVMExt* vm = Runtime::Current()->GetJavaVM();
374 IndirectReferenceTable& weak_globals = vm->weak_globals;
375 MutexLock mu(&vm->weak_globals_lock);
376 result = weak_globals.Get(ref);
377 if (result == kClearedJniWeakGlobal) {
378 // This is a special case where it's okay to return NULL.
379 return NULL;
380 }
381 break;
382 }
383 case kInvalid:
384 default:
385 if (false /*gDvmJni.workAroundAppJniBugs*/) { // TODO
386 // Assume an invalid local reference is actually a direct pointer.
387 return reinterpret_cast<T>(obj);
388 }
389 LOG(FATAL) << "Invalid indirect reference " << obj;
390 return reinterpret_cast<T>(kInvalidIndirectRefObject);
391 }
392
393 if (result == NULL) {
394 LOG(FATAL) << "JNI ERROR (app bug): use of deleted " << kind << ": "
395 << obj;
396 }
397 return reinterpret_cast<T>(result);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -0700398}
399
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700400void CreateInvokeStub(Assembler* assembler, Method* method);
401
402bool EnsureInvokeStub(Method* method) {
403 if (method->GetInvokeStub() != NULL) {
404 return true;
405 }
406 // TODO: use signature to find a matching stub
407 // TODO: failed, acquire a lock on the stub table
408 Assembler assembler;
409 CreateInvokeStub(&assembler, method);
410 // TODO: store native_entry in the stub table
411 int prot = PROT_READ | PROT_WRITE | PROT_EXEC;
412 size_t length = assembler.CodeSize();
413 void* addr = mmap(NULL, length, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
414 if (addr == MAP_FAILED) {
415 PLOG(FATAL) << "mmap failed";
416 }
417 MemoryRegion region(addr, length);
418 assembler.FinalizeInstructions(region);
419 method->SetInvokeStub(reinterpret_cast<Method::InvokeStub*>(region.pointer()));
420 return true;
421}
422
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700423byte* CreateArgArray(ScopedJniThreadState& ts, Method* method, va_list ap) {
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700424 size_t num_bytes = method->NumArgArrayBytes();
425 scoped_array<byte> arg_array(new byte[num_bytes]);
426 const StringPiece& shorty = method->GetShorty();
Ian Rogers4dd71f12011-08-16 14:16:02 -0700427 for (int i = 1, offset = 0; i < shorty.size(); ++i) {
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700428 switch (shorty[i]) {
429 case 'Z':
430 case 'B':
431 case 'C':
432 case 'S':
433 case 'I':
434 *reinterpret_cast<int32_t*>(&arg_array[offset]) = va_arg(ap, jint);
435 offset += 4;
436 break;
437 case 'F':
438 *reinterpret_cast<float*>(&arg_array[offset]) = va_arg(ap, jdouble);
439 offset += 4;
440 break;
441 case 'L': {
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700442 Object* obj = Decode<Object*>(ts, va_arg(ap, jobject));
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700443 *reinterpret_cast<Object**>(&arg_array[offset]) = obj;
444 offset += sizeof(Object*);
445 break;
446 }
447 case 'D':
448 *reinterpret_cast<double*>(&arg_array[offset]) = va_arg(ap, jdouble);
449 offset += 8;
450 break;
451 case 'J':
452 *reinterpret_cast<int64_t*>(&arg_array[offset]) = va_arg(ap, jlong);
453 offset += 8;
454 break;
455 }
456 }
457 return arg_array.release();
458}
459
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700460byte* CreateArgArray(ScopedJniThreadState& ts, Method* method, jvalue* args) {
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700461 size_t num_bytes = method->NumArgArrayBytes();
462 scoped_array<byte> arg_array(new byte[num_bytes]);
463 const StringPiece& shorty = method->GetShorty();
Ian Rogers4dd71f12011-08-16 14:16:02 -0700464 for (int i = 1, offset = 0; i < shorty.size(); ++i) {
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700465 switch (shorty[i]) {
466 case 'Z':
467 case 'B':
468 case 'C':
469 case 'S':
470 case 'I':
471 *reinterpret_cast<uint32_t*>(&arg_array[offset]) = args[i - 1].i;
472 offset += 4;
473 break;
474 case 'F':
475 *reinterpret_cast<float*>(&arg_array[offset]) = args[i - 1].f;
476 offset += 4;
477 break;
478 case 'L': {
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700479 Object* obj = Decode<Object*>(ts, args[i - 1].l);
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700480 *reinterpret_cast<Object**>(&arg_array[offset]) = obj;
481 offset += sizeof(Object*);
482 break;
483 }
484 case 'D':
485 *reinterpret_cast<double*>(&arg_array[offset]) = args[i - 1].d;
486 offset += 8;
487 break;
488 case 'J':
489 *reinterpret_cast<uint64_t*>(&arg_array[offset]) = args[i - 1].j;
490 offset += 8;
491 break;
492 }
493 }
494 return arg_array.release();
495}
496
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700497JValue InvokeWithArgArray(ScopedJniThreadState& ts,
498 Object* obj, jmethodID method_id, byte* args) {
Elliott Hughesf2682d52011-08-15 16:37:04 -0700499 // TODO: DecodeReference
500 Method* method = reinterpret_cast<Method*>(method_id);
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700501 // Call the invoke stub associated with the method
502 // Pass everything as arguments
503 const Method::InvokeStub* stub = method->GetInvokeStub();
504 CHECK(stub != NULL);
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700505 JValue result;
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700506 (*stub)(method, obj, ts.Self(), args, &result);
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700507 return result;
508}
509
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700510JValue InvokeWithJValues(ScopedJniThreadState& ts,
511 Object* obj, jmethodID method_id, jvalue* args) {
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700512 Method* method = reinterpret_cast<Method*>(method_id);
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700513 scoped_array<byte> arg_array(CreateArgArray(ts, method, args));
514 return InvokeWithArgArray(ts, obj, method_id, arg_array.get());
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700515}
516
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700517JValue InvokeWithVarArgs(ScopedJniThreadState& ts,
518 Object* obj, jmethodID method_id, va_list args) {
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700519 Method* method = reinterpret_cast<Method*>(method_id);
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700520 scoped_array<byte> arg_array(CreateArgArray(ts, method, args));
521 return InvokeWithArgArray(ts, obj, method_id, arg_array.get());
Carl Shapiro9b9ba282011-08-14 15:30:39 -0700522}
523
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700524jint GetVersion(JNIEnv* env) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700525 ScopedJniThreadState ts(env);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700526 return JNI_VERSION_1_6;
527}
528
Elliott Hughesb20a5542011-08-12 18:03:12 -0700529jclass DefineClass(JNIEnv* env, const char*, jobject, const jbyte*, jsize) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700530 ScopedJniThreadState ts(env);
Elliott Hughesb20a5542011-08-12 18:03:12 -0700531 LOG(WARNING) << "JNI DefineClass is not supported";
Carl Shapiroea4dca82011-08-01 13:45:38 -0700532 return NULL;
533}
534
Elliott Hughes6b436852011-08-12 10:16:44 -0700535// Section 12.3.2 of the JNI spec describes JNI class descriptors. They're
536// separated with slashes but aren't wrapped with "L;" like regular descriptors
537// (i.e. "a/b/C" rather than "La/b/C;"). Arrays of reference types are an
538// exception; there the "L;" must be present ("[La/b/C;"). Historically we've
539// supported names with dots too (such as "a.b.C").
540std::string NormalizeJniClassDescriptor(const char* name) {
541 std::string result;
542 // Add the missing "L;" if necessary.
543 if (name[0] == '[') {
544 result = name;
545 } else {
546 result += 'L';
547 result += name;
548 result += ';';
549 }
550 // Rewrite '.' as '/' for backwards compatibility.
Elliott Hughesa5b897e2011-08-16 11:33:06 -0700551 if (result.find('.') != std::string::npos) {
552 LOG(WARNING) << "Call to JNI FindClass with dots in name: "
553 << "\"" << name << "\"";
554 std::replace(result.begin(), result.end(), '.', '/');
Elliott Hughes6b436852011-08-12 10:16:44 -0700555 }
556 return result;
557}
558
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700559jclass FindClass(JNIEnv* env, const char* name) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700560 ScopedJniThreadState ts(env);
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700561 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Elliott Hughes6b436852011-08-12 10:16:44 -0700562 std::string descriptor(NormalizeJniClassDescriptor(name));
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700563 // TODO: need to get the appropriate ClassLoader.
Elliott Hughes6b436852011-08-12 10:16:44 -0700564 Class* c = class_linker->FindClass(descriptor, NULL);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -0700565 return AddLocalReference<jclass>(ts, c);
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700566}
567
568jmethodID FromReflectedMethod(JNIEnv* env, jobject method) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700569 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700570 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700571 return NULL;
572}
573
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700574jfieldID FromReflectedField(JNIEnv* env, jobject field) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700575 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700576 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700577 return NULL;
578}
579
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700580jobject ToReflectedMethod(JNIEnv* env, jclass cls,
581 jmethodID methodID, jboolean isStatic) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700582 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700583 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700584 return NULL;
585}
586
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700587jclass GetSuperclass(JNIEnv* env, jclass sub) {
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 -0700593jboolean IsAssignableFrom(JNIEnv* env, jclass sub, jclass sup) {
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 JNI_FALSE;
597}
598
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700599jobject ToReflectedField(JNIEnv* env, jclass cls,
600 jfieldID fieldID, 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 -0700606jint Throw(JNIEnv* env, jthrowable obj) {
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 0;
610}
611
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700612jint ThrowNew(JNIEnv* env, jclass clazz, const char* msg) {
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 0;
616}
617
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700618jthrowable ExceptionOccurred(JNIEnv* env) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700619 ScopedJniThreadState ts(env);
Ian Rogers4dd71f12011-08-16 14:16:02 -0700620 Object* exception = ts.Self()->GetException();
621 if (exception == NULL) {
622 return NULL;
623 } else {
624 // TODO: if adding a local reference failing causes the VM to abort
625 // then the following check will never occur.
626 jthrowable localException = AddLocalReference<jthrowable>(ts, exception);
627 if (localException == NULL) {
628 // We were unable to add a new local reference, and threw a new
629 // exception. We can't return "exception", because it's not a
630 // local reference. So we have to return NULL, indicating that
631 // there was no exception, even though it's pretty much raining
632 // exceptions in here.
633 LOG(WARNING) << "JNI WARNING: addLocal/exception combo";
634 }
635 return localException;
636 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700637}
638
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700639void ExceptionDescribe(JNIEnv* env) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700640 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700641 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700642}
643
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700644void ExceptionClear(JNIEnv* env) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700645 ScopedJniThreadState ts(env);
Elliott Hughesb20a5542011-08-12 18:03:12 -0700646 ts.Self()->ClearException();
Carl Shapiroea4dca82011-08-01 13:45:38 -0700647}
648
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700649void FatalError(JNIEnv* env, const char* msg) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700650 ScopedJniThreadState ts(env);
Elliott Hughesb20a5542011-08-12 18:03:12 -0700651 LOG(FATAL) << "JNI FatalError called: " << msg;
Carl Shapiroea4dca82011-08-01 13:45:38 -0700652}
653
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700654jint PushLocalFrame(JNIEnv* env, jint cap) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700655 ScopedJniThreadState ts(env);
Elliott Hughes0af55432011-08-17 18:37:28 -0700656 UNIMPLEMENTED(WARNING) << "ignoring PushLocalFrame(" << cap << ")";
657 return JNI_OK;
Carl Shapiroea4dca82011-08-01 13:45:38 -0700658}
659
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700660jobject PopLocalFrame(JNIEnv* env, jobject res) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700661 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700662 UNIMPLEMENTED(WARNING) << "ignoring PopLocalFrame " << res;
Elliott Hughes0af55432011-08-17 18:37:28 -0700663 return res;
Carl Shapiroea4dca82011-08-01 13:45:38 -0700664}
665
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700666jobject NewGlobalRef(JNIEnv* env, jobject lobj) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700667 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700668 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700669 return NULL;
670}
671
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700672void DeleteGlobalRef(JNIEnv* env, jobject gref) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700673 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700674 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700675}
676
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700677void DeleteLocalRef(JNIEnv* env, jobject obj) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700678 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700679
680 if (obj == NULL) {
681 return;
682 }
683
684 IndirectReferenceTable& locals = ts.Env()->locals;
685
686 uint32_t cookie = IRT_FIRST_SEGMENT; // TODO
687 if (!locals.Remove(cookie, obj)) {
688 // Attempting to delete a local reference that is not in the
689 // topmost local reference frame is a no-op. DeleteLocalRef returns
690 // void and doesn't throw any exceptions, but we should probably
691 // complain about it so the user will notice that things aren't
692 // going quite the way they expect.
693 LOG(WARNING) << "JNI WARNING: DeleteLocalRef(" << obj << ") "
694 << "failed to find entry";
695 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700696}
697
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700698jboolean IsSameObject(JNIEnv* env, jobject obj1, jobject obj2) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700699 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700700 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700701 return JNI_FALSE;
702}
703
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700704jobject NewLocalRef(JNIEnv* env, jobject ref) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700705 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700706 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700707 return NULL;
708}
709
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700710jint EnsureLocalCapacity(JNIEnv* env, jint) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700711 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700712 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700713 return 0;
714}
715
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700716jobject AllocObject(JNIEnv* env, jclass clazz) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700717 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700718 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700719 return NULL;
720}
721
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700722jobject NewObject(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700723 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700724 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700725 return NULL;
726}
727
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700728jobject NewObjectV(JNIEnv* env,
729 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700730 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700731 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700732 return NULL;
733}
734
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700735jobject NewObjectA(JNIEnv* env,
736 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700737 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700738 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700739 return NULL;
740}
741
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700742jclass GetObjectClass(JNIEnv* env, jobject obj) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700743 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700744 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700745 return NULL;
746}
747
Ian Rogers4dd71f12011-08-16 14:16:02 -0700748jboolean IsInstanceOf(JNIEnv* env, jobject jobj, jclass clazz) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700749 ScopedJniThreadState ts(env);
Ian Rogers4dd71f12011-08-16 14:16:02 -0700750 CHECK_NE(static_cast<jclass>(NULL), clazz);
751 if (jobj == NULL) {
752 // NB. JNI is different from regular Java instanceof in this respect
753 return JNI_TRUE;
754 } else {
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700755 Object* obj = Decode<Object*>(ts, jobj);
756 Class* klass = Decode<Class*>(ts, clazz);
Ian Rogers4dd71f12011-08-16 14:16:02 -0700757 return Object::InstanceOf(obj, klass) ? JNI_TRUE : JNI_FALSE;
758 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700759}
760
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700761jmethodID GetMethodID(JNIEnv* env,
762 jclass clazz, const char* name, const char* sig) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700763 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700764 Class* klass = Decode<Class*>(ts, clazz);
Carl Shapiro83ab4f32011-08-15 20:21:39 -0700765 if (!klass->IsInitialized()) {
766 // TODO: initialize the class
767 }
768 Method* method = klass->FindVirtualMethod(name, sig);
769 if (method == NULL) {
770 // No virtual method matching the signature. Search declared
771 // private methods and constructors.
772 method = klass->FindDeclaredDirectMethod(name, sig);
773 }
Ian Rogers4dd71f12011-08-16 14:16:02 -0700774 if (method == NULL) {
775 Thread* self = Thread::Current();
776 std::string class_name = klass->GetDescriptor().ToString();
777 // TODO: pretty print method names through a single routine
778 self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
779 "no method \"%s.%s%s\"",
780 class_name.c_str(), name, sig);
Carl Shapiro83ab4f32011-08-15 20:21:39 -0700781 return NULL;
Ian Rogers4dd71f12011-08-16 14:16:02 -0700782 } else if (method->IsStatic()) {
783 Thread* self = Thread::Current();
784 std::string class_name = klass->GetDescriptor().ToString();
785 // TODO: pretty print method names through a single routine
786 self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
787 "method \"%s.%s%s\" is static",
788 class_name.c_str(), name, sig);
Carl Shapiro83ab4f32011-08-15 20:21:39 -0700789 return NULL;
Ian Rogers4dd71f12011-08-16 14:16:02 -0700790 } else {
791 // TODO: create a JNI weak global reference for method
792 bool success = EnsureInvokeStub(method);
793 if (!success) {
794 // TODO: throw OutOfMemoryException
795 return NULL;
796 }
797 return reinterpret_cast<jmethodID>(method);
Carl Shapiro83ab4f32011-08-15 20:21:39 -0700798 }
Carl Shapiroea4dca82011-08-01 13:45:38 -0700799}
800
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700801jobject CallObjectMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700802 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700803 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700804 return NULL;
805}
806
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700807jobject CallObjectMethodV(JNIEnv* env,
808 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700809 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700810 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700811 return NULL;
812}
813
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700814jobject CallObjectMethodA(JNIEnv* env,
815 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700816 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700817 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700818 return NULL;
819}
820
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700821jboolean CallBooleanMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700822 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700823 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700824 return JNI_FALSE;
825}
826
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700827jboolean CallBooleanMethodV(JNIEnv* env,
828 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700829 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700830 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700831 return JNI_FALSE;
832}
833
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700834jboolean CallBooleanMethodA(JNIEnv* env,
835 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700836 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700837 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700838 return JNI_FALSE;
839}
840
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700841jbyte CallByteMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700842 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700843 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700844 return 0;
845}
846
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700847jbyte CallByteMethodV(JNIEnv* env,
848 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700849 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700850 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700851 return 0;
852}
853
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700854jbyte CallByteMethodA(JNIEnv* env,
855 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700856 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700857 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700858 return 0;
859}
860
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700861jchar CallCharMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700862 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700863 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700864 return 0;
865}
866
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700867jchar CallCharMethodV(JNIEnv* env,
868 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700869 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700870 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700871 return 0;
872}
873
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700874jchar CallCharMethodA(JNIEnv* env,
875 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700876 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700877 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700878 return 0;
879}
880
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700881jshort CallShortMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700882 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700883 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700884 return 0;
885}
886
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700887jshort CallShortMethodV(JNIEnv* env,
888 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700889 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700890 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700891 return 0;
892}
893
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700894jshort CallShortMethodA(JNIEnv* env,
895 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700896 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700897 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700898 return 0;
899}
900
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700901jint CallIntMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700902 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700903 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700904 return 0;
905}
906
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700907jint CallIntMethodV(JNIEnv* env,
908 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700909 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700910 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700911 return 0;
912}
913
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700914jint CallIntMethodA(JNIEnv* env,
915 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700916 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700917 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700918 return 0;
919}
920
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700921jlong CallLongMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700922 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700923 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700924 return 0;
925}
926
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700927jlong CallLongMethodV(JNIEnv* env,
928 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700929 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700930 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700931 return 0;
932}
933
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700934jlong CallLongMethodA(JNIEnv* env,
935 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700936 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700937 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700938 return 0;
939}
940
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700941jfloat CallFloatMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700942 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700943 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700944 return 0;
945}
946
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700947jfloat CallFloatMethodV(JNIEnv* env,
948 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700949 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700950 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700951 return 0;
952}
953
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700954jfloat CallFloatMethodA(JNIEnv* env,
955 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700956 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700957 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700958 return 0;
959}
960
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700961jdouble CallDoubleMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700962 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700963 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700964 return 0;
965}
966
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700967jdouble CallDoubleMethodV(JNIEnv* env,
968 jobject obj, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700969 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700970 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700971 return 0;
972}
973
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700974jdouble CallDoubleMethodA(JNIEnv* env,
975 jobject obj, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700976 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700977 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700978 return 0;
979}
980
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700981void CallVoidMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700982 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700983 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700984}
985
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700986void CallVoidMethodV(JNIEnv* env, jobject obj,
987 jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700988 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700989 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700990}
991
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700992void CallVoidMethodA(JNIEnv* env, jobject obj,
993 jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -0700994 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700995 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -0700996}
997
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700998jobject CallNonvirtualObjectMethod(JNIEnv* env,
999 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001000 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001001 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001002 return NULL;
1003}
1004
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001005jobject CallNonvirtualObjectMethodV(JNIEnv* env,
1006 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001007 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001008 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001009 return NULL;
1010}
1011
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001012jobject CallNonvirtualObjectMethodA(JNIEnv* env,
1013 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001014 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001015 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001016 return NULL;
1017}
1018
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001019jboolean CallNonvirtualBooleanMethod(JNIEnv* env,
1020 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001021 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001022 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001023 return JNI_FALSE;
1024}
1025
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001026jboolean CallNonvirtualBooleanMethodV(JNIEnv* env,
1027 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001028 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001029 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001030 return JNI_FALSE;
1031}
1032
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001033jboolean CallNonvirtualBooleanMethodA(JNIEnv* env,
1034 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001035 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001036 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001037 return JNI_FALSE;
1038}
1039
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001040jbyte CallNonvirtualByteMethod(JNIEnv* env,
1041 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001042 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001043 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001044 return 0;
1045}
1046
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001047jbyte CallNonvirtualByteMethodV(JNIEnv* env,
1048 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001049 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001050 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001051 return 0;
1052}
1053
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001054jbyte CallNonvirtualByteMethodA(JNIEnv* env,
1055 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001056 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001057 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001058 return 0;
1059}
1060
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001061jchar CallNonvirtualCharMethod(JNIEnv* env,
1062 jobject obj, jclass clazz, 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 return 0;
1066}
1067
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001068jchar CallNonvirtualCharMethodV(JNIEnv* env,
1069 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001070 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001071 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001072 return 0;
1073}
1074
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001075jchar CallNonvirtualCharMethodA(JNIEnv* env,
1076 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001077 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001078 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001079 return 0;
1080}
1081
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001082jshort CallNonvirtualShortMethod(JNIEnv* env,
1083 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001084 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001085 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001086 return 0;
1087}
1088
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001089jshort CallNonvirtualShortMethodV(JNIEnv* env,
1090 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001091 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001092 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001093 return 0;
1094}
1095
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001096jshort CallNonvirtualShortMethodA(JNIEnv* env,
1097 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001098 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001099 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001100 return 0;
1101}
1102
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001103jint CallNonvirtualIntMethod(JNIEnv* env,
1104 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001105 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001106 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001107 return 0;
1108}
1109
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001110jint CallNonvirtualIntMethodV(JNIEnv* env,
1111 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001112 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001113 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001114 return 0;
1115}
1116
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001117jint CallNonvirtualIntMethodA(JNIEnv* env,
1118 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001119 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001120 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001121 return 0;
1122}
1123
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001124jlong CallNonvirtualLongMethod(JNIEnv* env,
1125 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001126 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001127 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001128 return 0;
1129}
1130
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001131jlong CallNonvirtualLongMethodV(JNIEnv* env,
1132 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001133 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001134 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001135 return 0;
1136}
1137
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001138jlong CallNonvirtualLongMethodA(JNIEnv* env,
1139 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001140 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001141 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001142 return 0;
1143}
1144
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001145jfloat CallNonvirtualFloatMethod(JNIEnv* env,
1146 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001147 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001148 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001149 return 0;
1150}
1151
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001152jfloat CallNonvirtualFloatMethodV(JNIEnv* env,
1153 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001154 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001155 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001156 return 0;
1157}
1158
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001159jfloat CallNonvirtualFloatMethodA(JNIEnv* env,
1160 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001161 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001162 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001163 return 0;
1164}
1165
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001166jdouble CallNonvirtualDoubleMethod(JNIEnv* env,
1167 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001168 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001169 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001170 return 0;
1171}
1172
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001173jdouble CallNonvirtualDoubleMethodV(JNIEnv* env,
1174 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001175 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001176 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001177 return 0;
1178}
1179
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001180jdouble CallNonvirtualDoubleMethodA(JNIEnv* env,
1181 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001182 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001183 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001184 return 0;
1185}
1186
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001187void CallNonvirtualVoidMethod(JNIEnv* env,
1188 jobject obj, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001189 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001190 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001191}
1192
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001193void CallNonvirtualVoidMethodV(JNIEnv* env,
1194 jobject obj, jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001195 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001196 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001197}
1198
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001199void CallNonvirtualVoidMethodA(JNIEnv* env,
1200 jobject obj, jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001201 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001202 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001203}
1204
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001205jfieldID GetFieldID(JNIEnv* env,
1206 jclass clazz, const char* name, const char* sig) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001207 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001208 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001209 return NULL;
1210}
1211
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001212jobject GetObjectField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001213 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001214 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001215 return NULL;
1216}
1217
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001218jboolean GetBooleanField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001219 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001220 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001221 return JNI_FALSE;
1222}
1223
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001224jbyte GetByteField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001225 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001226 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001227 return 0;
1228}
1229
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001230jchar GetCharField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001231 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001232 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001233 return 0;
1234}
1235
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001236jshort GetShortField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001237 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001238 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001239 return 0;
1240}
1241
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001242jint GetIntField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001243 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001244 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001245 return 0;
1246}
1247
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001248jlong GetLongField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001249 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001250 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001251 return 0;
1252}
1253
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001254jfloat GetFloatField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001255 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001256 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001257 return 0;
1258}
1259
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001260jdouble GetDoubleField(JNIEnv* env, jobject obj, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001261 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001262 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001263 return 0;
1264}
1265
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001266void SetObjectField(JNIEnv* env, jobject obj, jfieldID fieldID, jobject val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001267 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001268 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001269}
1270
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001271void SetBooleanField(JNIEnv* env, jobject obj, jfieldID fieldID, jboolean val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001272 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001273 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001274}
1275
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001276void SetByteField(JNIEnv* env, jobject obj, jfieldID fieldID, jbyte val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001277 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001278 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001279}
1280
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001281void SetCharField(JNIEnv* env, jobject obj, jfieldID fieldID, jchar val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001282 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001283 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001284}
1285
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001286void SetShortField(JNIEnv* env, jobject obj, jfieldID fieldID, jshort val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001287 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001288 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001289}
1290
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001291void SetIntField(JNIEnv* env, jobject obj, jfieldID fieldID, jint val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001292 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001293 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001294}
1295
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001296void SetLongField(JNIEnv* env, jobject obj, jfieldID fieldID, jlong val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001297 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001298 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001299}
1300
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001301void SetFloatField(JNIEnv* env, jobject obj, jfieldID fieldID, jfloat val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001302 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001303 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001304}
1305
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001306void SetDoubleField(JNIEnv* env, jobject obj, jfieldID fieldID, jdouble val) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001307 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001308 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001309}
1310
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001311jmethodID GetStaticMethodID(JNIEnv* env,
1312 jclass clazz, const char* name, const char* sig) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001313 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001314 Class* klass = Decode<Class*>(ts, clazz);
Carl Shapiro83ab4f32011-08-15 20:21:39 -07001315 if (!klass->IsInitialized()) {
1316 // TODO: initialize the class
1317 }
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001318 Method* method = klass->FindDirectMethod(name, sig);
Ian Rogers4dd71f12011-08-16 14:16:02 -07001319 if (method == NULL) {
1320 Thread* self = Thread::Current();
1321 std::string class_name = klass->GetDescriptor().ToString();
1322 // TODO: pretty print method names through a single routine
1323 // TODO: may want to FindVirtualMethod to give more informative error
1324 // message here
1325 self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
1326 "no method \"%s.%s%s\"",
1327 class_name.c_str(), name, sig);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001328 return NULL;
Ian Rogers4dd71f12011-08-16 14:16:02 -07001329 } else if (!method->IsStatic()) {
1330 Thread* self = Thread::Current();
1331 std::string class_name = klass->GetDescriptor().ToString();
1332 // TODO: pretty print method names through a single routine
1333 self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
1334 "method \"%s.%s%s\" is not static",
1335 class_name.c_str(), name, sig);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001336 return NULL;
Ian Rogers4dd71f12011-08-16 14:16:02 -07001337 } else {
1338 // TODO: create a JNI weak global reference for method
1339 bool success = EnsureInvokeStub(method);
1340 if (!success) {
1341 // TODO: throw OutOfMemoryException
1342 return NULL;
1343 }
1344 return reinterpret_cast<jmethodID>(method);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001345 }
Carl Shapiroea4dca82011-08-01 13:45:38 -07001346}
1347
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001348jobject CallStaticObjectMethod(JNIEnv* env,
1349 jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001350 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001351 va_list ap;
1352 va_start(ap, methodID);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001353 JValue result = InvokeWithVarArgs(ts, NULL, methodID, ap);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001354 return AddLocalReference<jobject>(ts, result.l);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001355}
1356
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001357jobject CallStaticObjectMethodV(JNIEnv* env,
1358 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001359 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001360 JValue result = InvokeWithVarArgs(ts, NULL, methodID, args);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001361 return AddLocalReference<jobject>(ts, result.l);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001362}
1363
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001364jobject CallStaticObjectMethodA(JNIEnv* env,
1365 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001366 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001367 JValue result = InvokeWithJValues(ts, NULL, methodID, args);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001368 return AddLocalReference<jobject>(ts, result.l);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001369}
1370
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001371jboolean CallStaticBooleanMethod(JNIEnv* env,
1372 jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001373 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001374 va_list ap;
1375 va_start(ap, methodID);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001376 return InvokeWithVarArgs(ts, NULL, methodID, ap).z;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001377}
1378
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001379jboolean CallStaticBooleanMethodV(JNIEnv* env,
1380 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001381 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001382 return InvokeWithVarArgs(ts, NULL, methodID, args).z;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001383}
1384
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001385jboolean CallStaticBooleanMethodA(JNIEnv* env,
1386 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001387 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001388 return InvokeWithJValues(ts, NULL, methodID, args).z;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001389}
1390
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001391jbyte CallStaticByteMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001392 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001393 va_list ap;
1394 va_start(ap, methodID);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001395 return InvokeWithVarArgs(ts, NULL, methodID, ap).b;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001396}
1397
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001398jbyte CallStaticByteMethodV(JNIEnv* env,
1399 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001400 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001401 return InvokeWithVarArgs(ts, NULL, methodID, args).b;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001402}
1403
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001404jbyte CallStaticByteMethodA(JNIEnv* env,
1405 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001406 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001407 return InvokeWithJValues(ts, NULL, methodID, args).b;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001408}
1409
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001410jchar CallStaticCharMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001411 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001412 va_list ap;
1413 va_start(ap, methodID);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001414 return InvokeWithVarArgs(ts, NULL, methodID, ap).c;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001415}
1416
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001417jchar CallStaticCharMethodV(JNIEnv* env,
1418 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001419 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001420 return InvokeWithVarArgs(ts, NULL, methodID, args).c;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001421}
1422
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001423jchar CallStaticCharMethodA(JNIEnv* env,
1424 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001425 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001426 return InvokeWithJValues(ts, NULL, methodID, args).c;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001427}
1428
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001429jshort CallStaticShortMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001430 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001431 va_list ap;
1432 va_start(ap, methodID);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001433 return InvokeWithVarArgs(ts, NULL, methodID, ap).s;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001434}
1435
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001436jshort CallStaticShortMethodV(JNIEnv* env,
1437 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001438 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001439 return InvokeWithVarArgs(ts, NULL, methodID, args).s;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001440}
1441
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001442jshort CallStaticShortMethodA(JNIEnv* env,
1443 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001444 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001445 return InvokeWithJValues(ts, NULL, methodID, args).s;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001446}
1447
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001448jint CallStaticIntMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001449 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001450 va_list ap;
1451 va_start(ap, methodID);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001452 return InvokeWithVarArgs(ts, NULL, methodID, ap).i;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001453}
1454
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001455jint CallStaticIntMethodV(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 return InvokeWithVarArgs(ts, NULL, methodID, args).i;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001459}
1460
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001461jint CallStaticIntMethodA(JNIEnv* env,
1462 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001463 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001464 return InvokeWithJValues(ts, NULL, methodID, args).i;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001465}
1466
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001467jlong CallStaticLongMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001468 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001469 va_list ap;
1470 va_start(ap, methodID);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001471 return InvokeWithVarArgs(ts, NULL, methodID, ap).j;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001472}
1473
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001474jlong CallStaticLongMethodV(JNIEnv* env,
1475 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001476 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001477 return InvokeWithVarArgs(ts, NULL, methodID, args).j;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001478}
1479
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001480jlong CallStaticLongMethodA(JNIEnv* env,
1481 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001482 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001483 return InvokeWithJValues(ts, NULL, methodID, args).j;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001484}
1485
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001486jfloat CallStaticFloatMethod(JNIEnv* env, jclass cls, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001487 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001488 va_list ap;
1489 va_start(ap, methodID);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001490 return InvokeWithVarArgs(ts, NULL, methodID, ap).f;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001491}
1492
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001493jfloat CallStaticFloatMethodV(JNIEnv* env,
1494 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001495 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001496 return InvokeWithVarArgs(ts, NULL, methodID, args).f;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001497}
1498
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001499jfloat CallStaticFloatMethodA(JNIEnv* env,
1500 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001501 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001502 return InvokeWithJValues(ts, NULL, methodID, args).f;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001503}
1504
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001505jdouble CallStaticDoubleMethod(JNIEnv* env, jclass cls, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001506 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001507 va_list ap;
1508 va_start(ap, methodID);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001509 return InvokeWithVarArgs(ts, NULL, methodID, ap).d;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001510}
1511
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001512jdouble CallStaticDoubleMethodV(JNIEnv* env,
1513 jclass clazz, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001514 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001515 return InvokeWithVarArgs(ts, NULL, methodID, args).d;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001516}
1517
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001518jdouble CallStaticDoubleMethodA(JNIEnv* env,
1519 jclass clazz, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001520 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001521 return InvokeWithJValues(ts, NULL, methodID, args).d;
Carl Shapiroea4dca82011-08-01 13:45:38 -07001522}
1523
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001524void CallStaticVoidMethod(JNIEnv* env, jclass cls, jmethodID methodID, ...) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001525 ScopedJniThreadState ts(env);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001526 va_list ap;
1527 va_start(ap, methodID);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001528 InvokeWithVarArgs(ts, NULL, methodID, ap);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001529}
1530
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001531void CallStaticVoidMethodV(JNIEnv* env,
1532 jclass cls, jmethodID methodID, va_list args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001533 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001534 InvokeWithVarArgs(ts, NULL, methodID, args);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001535}
1536
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001537void CallStaticVoidMethodA(JNIEnv* env,
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001538 jclass cls, jmethodID methodID, jvalue* args) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001539 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001540 InvokeWithJValues(ts, NULL, methodID, args);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001541}
1542
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001543jfieldID GetStaticFieldID(JNIEnv* env,
1544 jclass clazz, const char* name, const char* sig) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001545 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001546 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001547 return 0;
1548}
1549
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001550jobject GetStaticObjectField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001551 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001552 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001553 return NULL;
1554}
1555
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001556jboolean GetStaticBooleanField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001557 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001558 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001559 return JNI_FALSE;
1560}
1561
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001562jbyte GetStaticByteField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001563 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001564 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001565 return 0;
1566}
1567
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001568jchar GetStaticCharField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001569 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001570 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001571 return 0;
1572}
1573
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001574jshort GetStaticShortField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001575 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001576 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001577 return 0;
1578}
1579
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001580jint GetStaticIntField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001581 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001582 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001583 return 0;
1584}
1585
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001586jlong GetStaticLongField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001587 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001588 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001589 return 0;
1590}
1591
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001592jfloat GetStaticFloatField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001593 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001594 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001595 return 0;
1596}
1597
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001598jdouble GetStaticDoubleField(JNIEnv* env, jclass clazz, jfieldID fieldID) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001599 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001600 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001601 return 0;
1602}
1603
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001604void SetStaticObjectField(JNIEnv* env,
1605 jclass clazz, jfieldID fieldID, jobject value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001606 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001607 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001608}
1609
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001610void SetStaticBooleanField(JNIEnv* env,
1611 jclass clazz, jfieldID fieldID, jboolean value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001612 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001613 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001614}
1615
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001616void SetStaticByteField(JNIEnv* env,
1617 jclass clazz, jfieldID fieldID, jbyte value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001618 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001619 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001620}
1621
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001622void SetStaticCharField(JNIEnv* env,
1623 jclass clazz, jfieldID fieldID, jchar value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001624 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001625 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001626}
1627
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001628void SetStaticShortField(JNIEnv* env,
1629 jclass clazz, jfieldID fieldID, jshort value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001630 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001631 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001632}
1633
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001634void SetStaticIntField(JNIEnv* env,
1635 jclass clazz, jfieldID fieldID, jint value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001636 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001637 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001638}
1639
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001640void SetStaticLongField(JNIEnv* env,
1641 jclass clazz, jfieldID fieldID, jlong value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001642 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001643 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001644}
1645
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001646void SetStaticFloatField(JNIEnv* env,
1647 jclass clazz, jfieldID fieldID, jfloat value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001648 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001649 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001650}
1651
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001652void SetStaticDoubleField(JNIEnv* env,
1653 jclass clazz, jfieldID fieldID, jdouble value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001654 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001655 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001656}
1657
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001658jstring NewString(JNIEnv* env, const jchar* unicode, jsize len) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001659 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001660 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001661 return NULL;
1662}
1663
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001664jsize GetStringLength(JNIEnv* env, jstring str) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001665 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001666 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001667 return 0;
1668}
1669
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001670const jchar* GetStringChars(JNIEnv* env, jstring str, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001671 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001672 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001673 return NULL;
1674}
1675
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001676void ReleaseStringChars(JNIEnv* env, jstring str, const jchar* chars) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001677 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001678 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001679}
1680
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001681jstring NewStringUTF(JNIEnv* env, const char* utf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001682 ScopedJniThreadState ts(env);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001683 if (utf == NULL) {
1684 return NULL;
1685 }
1686 size_t char_count = String::ModifiedUtf8Len(utf);
1687 String* result = String::AllocFromModifiedUtf8(char_count, utf);
1688 return AddLocalReference<jstring>(ts, result);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001689}
1690
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001691jsize GetStringUTFLength(JNIEnv* env, jstring str) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001692 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001693 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001694 return 0;
1695}
1696
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001697const char* GetStringUTFChars(JNIEnv* env, jstring str, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001698 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001699 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001700 return NULL;
1701}
1702
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001703void ReleaseStringUTFChars(JNIEnv* env, jstring str, const char* chars) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001704 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001705 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001706}
1707
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001708jsize GetArrayLength(JNIEnv* env, jarray array) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001709 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001710 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001711 return 0;
1712}
1713
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001714jobject GetObjectArrayElement(JNIEnv* env, jobjectArray array, jsize index) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001715 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001716 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001717 return NULL;
1718}
1719
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001720void SetObjectArrayElement(JNIEnv* env,
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001721 jobjectArray java_array, jsize index, jobject java_value) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001722 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001723 ObjectArray<Object>* array = Decode<ObjectArray<Object>*>(ts, java_array);
1724 Object* value = Decode<Object*>(ts, java_value);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001725 array->Set(index, value);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001726}
1727
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001728template<typename JniT, typename ArtT>
1729JniT NewPrimitiveArray(ScopedJniThreadState& ts, jsize length) {
1730 CHECK_GE(length, 0); // TODO: ReportJniError
1731 ArtT* result = ArtT::Alloc(length);
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001732 return AddLocalReference<JniT>(ts, result);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001733}
1734
Elliott Hughesf2682d52011-08-15 16:37:04 -07001735jbooleanArray NewBooleanArray(JNIEnv* env, jsize length) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001736 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001737 return NewPrimitiveArray<jbooleanArray, BooleanArray>(ts, length);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001738}
1739
Elliott Hughesf2682d52011-08-15 16:37:04 -07001740jbyteArray NewByteArray(JNIEnv* env, jsize length) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001741 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001742 return NewPrimitiveArray<jbyteArray, ByteArray>(ts, length);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001743}
1744
Elliott Hughesf2682d52011-08-15 16:37:04 -07001745jcharArray NewCharArray(JNIEnv* env, jsize length) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001746 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001747 return NewPrimitiveArray<jcharArray, CharArray>(ts, length);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001748}
1749
Elliott Hughesf2682d52011-08-15 16:37:04 -07001750jdoubleArray NewDoubleArray(JNIEnv* env, jsize length) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001751 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001752 return NewPrimitiveArray<jdoubleArray, DoubleArray>(ts, length);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001753}
1754
Elliott Hughesf2682d52011-08-15 16:37:04 -07001755jfloatArray NewFloatArray(JNIEnv* env, jsize length) {
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001756 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001757 return NewPrimitiveArray<jfloatArray, FloatArray>(ts, length);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001758}
1759
Elliott Hughesf2682d52011-08-15 16:37:04 -07001760jintArray NewIntArray(JNIEnv* env, jsize length) {
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001761 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001762 return NewPrimitiveArray<jintArray, IntArray>(ts, length);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001763}
1764
Elliott Hughesf2682d52011-08-15 16:37:04 -07001765jlongArray NewLongArray(JNIEnv* env, jsize length) {
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001766 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001767 return NewPrimitiveArray<jlongArray, LongArray>(ts, length);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001768}
1769
Elliott Hughesf2682d52011-08-15 16:37:04 -07001770jobjectArray NewObjectArray(JNIEnv* env, jsize length, jclass element_jclass, jobject initial_element) {
Elliott Hughesd8ddfd52011-08-15 14:32:53 -07001771 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001772 CHECK_GE(length, 0); // TODO: ReportJniError
1773
1774 // Compute the array class corresponding to the given element class.
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001775 Class* element_class = Decode<Class*>(ts, element_jclass);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001776 std::string descriptor;
1777 descriptor += "[";
1778 descriptor += element_class->GetDescriptor().ToString();
1779
1780 // Find the class.
1781 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
1782 // TODO: need to get the appropriate ClassLoader.
1783 Class* array_class = class_linker->FindClass(descriptor, NULL);
1784 if (array_class == NULL) {
1785 return NULL;
1786 }
1787
1788 ObjectArray<Object>* result = ObjectArray<Object>::Alloc(array_class, length);
1789 CHECK(initial_element == NULL); // TODO: support initial_element
Elliott Hughes8a26c5c2011-08-15 18:35:43 -07001790 return AddLocalReference<jobjectArray>(ts, result);
Elliott Hughesf2682d52011-08-15 16:37:04 -07001791}
1792
1793jshortArray NewShortArray(JNIEnv* env, jsize length) {
1794 ScopedJniThreadState ts(env);
1795 return NewPrimitiveArray<jshortArray, ShortArray>(ts, length);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001796}
1797
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001798jboolean* GetBooleanArrayElements(JNIEnv* env,
1799 jbooleanArray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001800 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001801 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001802 return NULL;
1803}
1804
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001805jbyte* GetByteArrayElements(JNIEnv* env, jbyteArray array, jboolean* isCopy) {
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 NULL;
1809}
1810
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001811jchar* GetCharArrayElements(JNIEnv* env, jcharArray array, 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 -07001817jshort* GetShortArrayElements(JNIEnv* env,
1818 jshortArray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001819 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001820 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001821 return NULL;
1822}
1823
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001824jint* GetIntArrayElements(JNIEnv* env, jintArray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001825 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001826 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001827 return NULL;
1828}
1829
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001830jlong* GetLongArrayElements(JNIEnv* env, jlongArray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001831 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001832 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001833 return NULL;
1834}
1835
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001836jfloat* GetFloatArrayElements(JNIEnv* env,
1837 jfloatArray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001838 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001839 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001840 return NULL;
1841}
1842
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001843jdouble* GetDoubleArrayElements(JNIEnv* env,
1844 jdoubleArray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001845 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001846 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001847 return NULL;
1848}
1849
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001850void ReleaseBooleanArrayElements(JNIEnv* env,
1851 jbooleanArray array, jboolean* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001852 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001853 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001854}
1855
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001856void ReleaseByteArrayElements(JNIEnv* env,
1857 jbyteArray array, jbyte* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001858 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001859 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001860}
1861
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001862void ReleaseCharArrayElements(JNIEnv* env,
1863 jcharArray array, jchar* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001864 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001865 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001866}
1867
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001868void ReleaseShortArrayElements(JNIEnv* env,
1869 jshortArray array, jshort* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001870 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001871 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001872}
1873
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001874void ReleaseIntArrayElements(JNIEnv* env,
1875 jintArray array, jint* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001876 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001877 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001878}
1879
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001880void ReleaseLongArrayElements(JNIEnv* env,
1881 jlongArray array, jlong* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001882 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001883 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001884}
1885
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001886void ReleaseFloatArrayElements(JNIEnv* env,
1887 jfloatArray array, jfloat* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001888 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001889 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001890}
1891
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001892void ReleaseDoubleArrayElements(JNIEnv* env,
1893 jdoubleArray array, jdouble* elems, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001894 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001895 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001896}
1897
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001898void GetBooleanArrayRegion(JNIEnv* env,
1899 jbooleanArray array, jsize start, jsize l, jboolean* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001900 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001901 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001902}
1903
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001904void GetByteArrayRegion(JNIEnv* env,
1905 jbyteArray array, jsize start, jsize len, jbyte* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001906 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001907 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001908}
1909
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001910void GetCharArrayRegion(JNIEnv* env,
1911 jcharArray array, jsize start, jsize len, jchar* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001912 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001913 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001914}
1915
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001916void GetShortArrayRegion(JNIEnv* env,
1917 jshortArray array, jsize start, jsize len, jshort* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001918 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001919 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001920}
1921
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001922void GetIntArrayRegion(JNIEnv* env,
1923 jintArray array, jsize start, jsize len, jint* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001924 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001925 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001926}
1927
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001928void GetLongArrayRegion(JNIEnv* env,
1929 jlongArray array, jsize start, jsize len, jlong* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001930 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001931 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001932}
1933
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001934void GetFloatArrayRegion(JNIEnv* env,
1935 jfloatArray array, jsize start, jsize len, jfloat* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001936 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001937 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001938}
1939
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001940void GetDoubleArrayRegion(JNIEnv* env,
1941 jdoubleArray array, jsize start, jsize len, jdouble* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001942 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001943 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001944}
1945
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001946void SetBooleanArrayRegion(JNIEnv* env,
1947 jbooleanArray array, jsize start, jsize l, const jboolean* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001948 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001949 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001950}
1951
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001952void SetByteArrayRegion(JNIEnv* env,
1953 jbyteArray array, jsize start, jsize len, const jbyte* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001954 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001955 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001956}
1957
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001958void SetCharArrayRegion(JNIEnv* env,
1959 jcharArray array, jsize start, jsize len, const jchar* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001960 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07001961 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07001962}
1963
Elliott Hughes40ef99e2011-08-11 17:44:34 -07001964void SetShortArrayRegion(JNIEnv* env,
1965 jshortArray array, jsize start, jsize len, const jshort* buf) {
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 SetIntArrayRegion(JNIEnv* env,
1971 jintArray array, jsize start, jsize len, const jint* buf) {
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 SetLongArrayRegion(JNIEnv* env,
1977 jlongArray array, jsize start, jsize len, const jlong* buf) {
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 SetFloatArrayRegion(JNIEnv* env,
1983 jfloatArray array, jsize start, jsize len, const jfloat* buf) {
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 SetDoubleArrayRegion(JNIEnv* env,
1989 jdoubleArray array, jsize start, jsize len, const jdouble* buf) {
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 -07001994jint RegisterNatives(JNIEnv* env,
1995 jclass clazz, const JNINativeMethod* methods, jint nMethods) {
Elliott Hughes22f40932011-08-12 13:06:37 -07001996 ScopedJniThreadState ts(env);
Elliott Hughesc5f7c912011-08-18 14:00:42 -07001997 Class* klass = Decode<Class*>(ts, clazz);
Ian Rogers4dd71f12011-08-16 14:16:02 -07001998 for(int i = 0; i < nMethods; i++) {
1999 const char* name = methods[i].name;
2000 const char* sig = methods[i].signature;
Elliott Hughes0af55432011-08-17 18:37:28 -07002001
2002 if (*sig == '!') {
2003 // TODO: fast jni. it's too noisy to log all these.
2004 ++sig;
2005 }
2006
Ian Rogers4dd71f12011-08-16 14:16:02 -07002007 Method* method = klass->FindDirectMethod(name, sig);
2008 if (method == NULL) {
2009 method = klass->FindVirtualMethod(name, sig);
2010 }
2011 if (method == NULL) {
2012 Thread* self = Thread::Current();
2013 std::string class_name = klass->GetDescriptor().ToString();
2014 // TODO: pretty print method names through a single routine
2015 self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
2016 "no method \"%s.%s%s\"",
2017 class_name.c_str(), name, sig);
2018 return JNI_ERR;
2019 } else if (!method->IsNative()) {
2020 Thread* self = Thread::Current();
2021 std::string class_name = klass->GetDescriptor().ToString();
2022 // TODO: pretty print method names through a single routine
2023 self->ThrowNewException("Ljava/lang/NoSuchMethodError;",
2024 "method \"%s.%s%s\" is not native",
2025 class_name.c_str(), name, sig);
2026 return JNI_ERR;
2027 }
2028 method->RegisterNative(methods[i].fnPtr);
2029 }
2030 return JNI_OK;
Carl Shapiroea4dca82011-08-01 13:45:38 -07002031}
2032
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002033jint UnregisterNatives(JNIEnv* env, jclass clazz) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002034 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002035 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002036 return 0;
2037}
2038
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002039jint MonitorEnter(JNIEnv* env, jobject obj) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002040 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002041 UNIMPLEMENTED(WARNING);
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002042 return 0;
2043}
2044
2045jint MonitorExit(JNIEnv* env, jobject obj) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002046 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002047 UNIMPLEMENTED(WARNING);
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002048 return 0;
2049}
2050
Elliott Hughesb20a5542011-08-12 18:03:12 -07002051jint GetJavaVM(JNIEnv* env, JavaVM** vm) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002052 ScopedJniThreadState ts(env);
Elliott Hughesf2682d52011-08-15 16:37:04 -07002053 Runtime* runtime = Runtime::Current();
2054 if (runtime != NULL) {
Elliott Hughes0af55432011-08-17 18:37:28 -07002055 *vm = reinterpret_cast<JavaVM*>(runtime->GetJavaVM());
Elliott Hughesf2682d52011-08-15 16:37:04 -07002056 } else {
2057 *vm = NULL;
2058 }
2059 return (*vm != NULL) ? JNI_OK : JNI_ERR;
Carl Shapiroea4dca82011-08-01 13:45:38 -07002060}
2061
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002062void GetStringRegion(JNIEnv* env,
2063 jstring str, jsize start, jsize len, jchar* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002064 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002065 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002066}
2067
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002068void GetStringUTFRegion(JNIEnv* env,
2069 jstring str, jsize start, jsize len, char* buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002070 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002071 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002072}
2073
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002074void* GetPrimitiveArrayCritical(JNIEnv* env,
2075 jarray array, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002076 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002077 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002078 return NULL;
2079}
2080
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002081void ReleasePrimitiveArrayCritical(JNIEnv* env,
2082 jarray array, void* carray, jint mode) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002083 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002084 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002085}
2086
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002087const jchar* GetStringCritical(JNIEnv* env, jstring s, jboolean* isCopy) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002088 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002089 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002090 return NULL;
2091}
2092
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002093void ReleaseStringCritical(JNIEnv* env, jstring s, const jchar* cstr) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002094 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002095 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002096}
2097
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002098jweak NewWeakGlobalRef(JNIEnv* env, jobject obj) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002099 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002100 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002101 return NULL;
2102}
2103
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002104void DeleteWeakGlobalRef(JNIEnv* env, jweak obj) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002105 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002106 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002107}
2108
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002109jboolean ExceptionCheck(JNIEnv* env) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002110 ScopedJniThreadState ts(env);
Elliott Hughesb20a5542011-08-12 18:03:12 -07002111 return ts.Self()->IsExceptionPending() ? JNI_TRUE : JNI_FALSE;
Carl Shapiroea4dca82011-08-01 13:45:38 -07002112}
2113
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002114jobject NewDirectByteBuffer(JNIEnv* env, void* address, jlong capacity) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002115 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002116 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002117 return NULL;
2118}
2119
2120
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002121void* GetDirectBufferAddress(JNIEnv* env, jobject buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002122 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002123 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002124 return NULL;
2125}
2126
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002127jlong GetDirectBufferCapacity(JNIEnv* env, jobject buf) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002128 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002129 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002130 return 0;
2131}
2132
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002133jobjectRefType GetObjectRefType(JNIEnv* env, jobject jobj) {
Elliott Hughes22f40932011-08-12 13:06:37 -07002134 ScopedJniThreadState ts(env);
Elliott Hughesc7ac37f2011-08-12 12:21:58 -07002135 UNIMPLEMENTED(FATAL);
Carl Shapiroea4dca82011-08-01 13:45:38 -07002136 return JNIInvalidRefType;
2137}
2138
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002139static const struct JNINativeInterface gNativeInterface = {
Carl Shapiroea4dca82011-08-01 13:45:38 -07002140 NULL, // reserved0.
2141 NULL, // reserved1.
2142 NULL, // reserved2.
2143 NULL, // reserved3.
2144 GetVersion,
2145 DefineClass,
2146 FindClass,
2147 FromReflectedMethod,
2148 FromReflectedField,
2149 ToReflectedMethod,
2150 GetSuperclass,
2151 IsAssignableFrom,
2152 ToReflectedField,
2153 Throw,
2154 ThrowNew,
2155 ExceptionOccurred,
2156 ExceptionDescribe,
2157 ExceptionClear,
2158 FatalError,
2159 PushLocalFrame,
2160 PopLocalFrame,
2161 NewGlobalRef,
2162 DeleteGlobalRef,
2163 DeleteLocalRef,
2164 IsSameObject,
2165 NewLocalRef,
2166 EnsureLocalCapacity,
2167 AllocObject,
2168 NewObject,
2169 NewObjectV,
2170 NewObjectA,
2171 GetObjectClass,
2172 IsInstanceOf,
2173 GetMethodID,
2174 CallObjectMethod,
2175 CallObjectMethodV,
2176 CallObjectMethodA,
2177 CallBooleanMethod,
2178 CallBooleanMethodV,
2179 CallBooleanMethodA,
2180 CallByteMethod,
2181 CallByteMethodV,
2182 CallByteMethodA,
2183 CallCharMethod,
2184 CallCharMethodV,
2185 CallCharMethodA,
2186 CallShortMethod,
2187 CallShortMethodV,
2188 CallShortMethodA,
2189 CallIntMethod,
2190 CallIntMethodV,
2191 CallIntMethodA,
2192 CallLongMethod,
2193 CallLongMethodV,
2194 CallLongMethodA,
2195 CallFloatMethod,
2196 CallFloatMethodV,
2197 CallFloatMethodA,
2198 CallDoubleMethod,
2199 CallDoubleMethodV,
2200 CallDoubleMethodA,
2201 CallVoidMethod,
2202 CallVoidMethodV,
2203 CallVoidMethodA,
2204 CallNonvirtualObjectMethod,
2205 CallNonvirtualObjectMethodV,
2206 CallNonvirtualObjectMethodA,
2207 CallNonvirtualBooleanMethod,
2208 CallNonvirtualBooleanMethodV,
2209 CallNonvirtualBooleanMethodA,
2210 CallNonvirtualByteMethod,
2211 CallNonvirtualByteMethodV,
2212 CallNonvirtualByteMethodA,
2213 CallNonvirtualCharMethod,
2214 CallNonvirtualCharMethodV,
2215 CallNonvirtualCharMethodA,
2216 CallNonvirtualShortMethod,
2217 CallNonvirtualShortMethodV,
2218 CallNonvirtualShortMethodA,
2219 CallNonvirtualIntMethod,
2220 CallNonvirtualIntMethodV,
2221 CallNonvirtualIntMethodA,
2222 CallNonvirtualLongMethod,
2223 CallNonvirtualLongMethodV,
2224 CallNonvirtualLongMethodA,
2225 CallNonvirtualFloatMethod,
2226 CallNonvirtualFloatMethodV,
2227 CallNonvirtualFloatMethodA,
2228 CallNonvirtualDoubleMethod,
2229 CallNonvirtualDoubleMethodV,
2230 CallNonvirtualDoubleMethodA,
2231 CallNonvirtualVoidMethod,
2232 CallNonvirtualVoidMethodV,
2233 CallNonvirtualVoidMethodA,
2234 GetFieldID,
2235 GetObjectField,
2236 GetBooleanField,
2237 GetByteField,
2238 GetCharField,
2239 GetShortField,
2240 GetIntField,
2241 GetLongField,
2242 GetFloatField,
2243 GetDoubleField,
2244 SetObjectField,
2245 SetBooleanField,
2246 SetByteField,
2247 SetCharField,
2248 SetShortField,
2249 SetIntField,
2250 SetLongField,
2251 SetFloatField,
2252 SetDoubleField,
2253 GetStaticMethodID,
2254 CallStaticObjectMethod,
2255 CallStaticObjectMethodV,
2256 CallStaticObjectMethodA,
2257 CallStaticBooleanMethod,
2258 CallStaticBooleanMethodV,
2259 CallStaticBooleanMethodA,
2260 CallStaticByteMethod,
2261 CallStaticByteMethodV,
2262 CallStaticByteMethodA,
2263 CallStaticCharMethod,
2264 CallStaticCharMethodV,
2265 CallStaticCharMethodA,
2266 CallStaticShortMethod,
2267 CallStaticShortMethodV,
2268 CallStaticShortMethodA,
2269 CallStaticIntMethod,
2270 CallStaticIntMethodV,
2271 CallStaticIntMethodA,
2272 CallStaticLongMethod,
2273 CallStaticLongMethodV,
2274 CallStaticLongMethodA,
2275 CallStaticFloatMethod,
2276 CallStaticFloatMethodV,
2277 CallStaticFloatMethodA,
2278 CallStaticDoubleMethod,
2279 CallStaticDoubleMethodV,
2280 CallStaticDoubleMethodA,
2281 CallStaticVoidMethod,
2282 CallStaticVoidMethodV,
2283 CallStaticVoidMethodA,
2284 GetStaticFieldID,
2285 GetStaticObjectField,
2286 GetStaticBooleanField,
2287 GetStaticByteField,
2288 GetStaticCharField,
2289 GetStaticShortField,
2290 GetStaticIntField,
2291 GetStaticLongField,
2292 GetStaticFloatField,
2293 GetStaticDoubleField,
2294 SetStaticObjectField,
2295 SetStaticBooleanField,
2296 SetStaticByteField,
2297 SetStaticCharField,
2298 SetStaticShortField,
2299 SetStaticIntField,
2300 SetStaticLongField,
2301 SetStaticFloatField,
2302 SetStaticDoubleField,
2303 NewString,
2304 GetStringLength,
2305 GetStringChars,
2306 ReleaseStringChars,
2307 NewStringUTF,
2308 GetStringUTFLength,
2309 GetStringUTFChars,
2310 ReleaseStringUTFChars,
2311 GetArrayLength,
2312 NewObjectArray,
2313 GetObjectArrayElement,
2314 SetObjectArrayElement,
2315 NewBooleanArray,
2316 NewByteArray,
2317 NewCharArray,
2318 NewShortArray,
2319 NewIntArray,
2320 NewLongArray,
2321 NewFloatArray,
2322 NewDoubleArray,
2323 GetBooleanArrayElements,
2324 GetByteArrayElements,
2325 GetCharArrayElements,
2326 GetShortArrayElements,
2327 GetIntArrayElements,
2328 GetLongArrayElements,
2329 GetFloatArrayElements,
2330 GetDoubleArrayElements,
2331 ReleaseBooleanArrayElements,
2332 ReleaseByteArrayElements,
2333 ReleaseCharArrayElements,
2334 ReleaseShortArrayElements,
2335 ReleaseIntArrayElements,
2336 ReleaseLongArrayElements,
2337 ReleaseFloatArrayElements,
2338 ReleaseDoubleArrayElements,
2339 GetBooleanArrayRegion,
2340 GetByteArrayRegion,
2341 GetCharArrayRegion,
2342 GetShortArrayRegion,
2343 GetIntArrayRegion,
2344 GetLongArrayRegion,
2345 GetFloatArrayRegion,
2346 GetDoubleArrayRegion,
2347 SetBooleanArrayRegion,
2348 SetByteArrayRegion,
2349 SetCharArrayRegion,
2350 SetShortArrayRegion,
2351 SetIntArrayRegion,
2352 SetLongArrayRegion,
2353 SetFloatArrayRegion,
2354 SetDoubleArrayRegion,
2355 RegisterNatives,
2356 UnregisterNatives,
2357 MonitorEnter,
2358 MonitorExit,
2359 GetJavaVM,
2360 GetStringRegion,
2361 GetStringUTFRegion,
2362 GetPrimitiveArrayCritical,
2363 ReleasePrimitiveArrayCritical,
2364 GetStringCritical,
2365 ReleaseStringCritical,
2366 NewWeakGlobalRef,
2367 DeleteWeakGlobalRef,
2368 ExceptionCheck,
2369 NewDirectByteBuffer,
2370 GetDirectBufferAddress,
2371 GetDirectBufferCapacity,
2372 GetObjectRefType,
2373};
2374
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002375static const size_t kMonitorsInitial = 32; // Arbitrary.
2376static const size_t kMonitorsMax = 4096; // Arbitrary sanity check.
2377
2378static const size_t kLocalsInitial = 64; // Arbitrary.
2379static const size_t kLocalsMax = 512; // Arbitrary sanity check.
Elliott Hughesbbd76712011-08-17 10:25:24 -07002380
Elliott Hughes515a5bc2011-08-17 11:08:34 -07002381JNIEnvExt::JNIEnvExt(Thread* self, bool check_jni)
Elliott Hughesbbd76712011-08-17 10:25:24 -07002382 : fns(&gNativeInterface),
2383 self(self),
Elliott Hughes515a5bc2011-08-17 11:08:34 -07002384 check_jni(check_jni),
Elliott Hughesbbd76712011-08-17 10:25:24 -07002385 critical(false),
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002386 monitors("monitors", kMonitorsInitial, kMonitorsMax),
2387 locals(kLocalsInitial, kLocalsMax, kLocal) {
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002388}
2389
Carl Shapiroea4dca82011-08-01 13:45:38 -07002390// JNI Invocation interface.
2391
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002392extern "C" jint JNI_CreateJavaVM(JavaVM** p_vm, void** p_env, void* vm_args) {
2393 const JavaVMInitArgs* args = static_cast<JavaVMInitArgs*>(vm_args);
2394 if (args->version < JNI_VERSION_1_2) {
2395 return JNI_EVERSION;
2396 }
2397 Runtime::Options options;
2398 for (int i = 0; i < args->nOptions; ++i) {
2399 JavaVMOption* option = &args->options[i];
Carl Shapirofc322c72011-07-27 00:20:01 -07002400 options.push_back(std::make_pair(StringPiece(option->optionString),
2401 option->extraInfo));
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002402 }
2403 bool ignore_unrecognized = args->ignoreUnrecognized;
Elliott Hughesf2682d52011-08-15 16:37:04 -07002404 Runtime* runtime = Runtime::Create(options, ignore_unrecognized);
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002405 if (runtime == NULL) {
2406 return JNI_ERR;
2407 } else {
2408 *p_env = reinterpret_cast<JNIEnv*>(Thread::Current()->GetJniEnv());
Elliott Hughes0af55432011-08-17 18:37:28 -07002409 *p_vm = reinterpret_cast<JavaVM*>(runtime->GetJavaVM());
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002410 return JNI_OK;
2411 }
2412}
2413
Elliott Hughesf2682d52011-08-15 16:37:04 -07002414extern "C" jint JNI_GetCreatedJavaVMs(JavaVM** vms, jsize, jsize* vm_count) {
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002415 Runtime* runtime = Runtime::Current();
2416 if (runtime == NULL) {
Elliott Hughesf2682d52011-08-15 16:37:04 -07002417 *vm_count = 0;
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002418 } else {
Elliott Hughesf2682d52011-08-15 16:37:04 -07002419 *vm_count = 1;
Elliott Hughes0af55432011-08-17 18:37:28 -07002420 vms[0] = reinterpret_cast<JavaVM*>(runtime->GetJavaVM());
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002421 }
2422 return JNI_OK;
2423}
2424
2425// Historically unsupported.
2426extern "C" jint JNI_GetDefaultJavaVMInitArgs(void* vm_args) {
2427 return JNI_ERR;
2428}
2429
Elliott Hughesf2682d52011-08-15 16:37:04 -07002430jint DestroyJavaVM(JavaVM* vm) {
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002431 if (vm == NULL) {
2432 return JNI_ERR;
2433 } else {
Elliott Hughesf2682d52011-08-15 16:37:04 -07002434 JavaVMExt* raw_vm = reinterpret_cast<JavaVMExt*>(vm);
2435 delete raw_vm->runtime;
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002436 return JNI_OK;
2437 }
2438}
2439
Elliott Hughesf2682d52011-08-15 16:37:04 -07002440jint AttachCurrentThread(JavaVM* vm, JNIEnv** p_env, void* thr_args) {
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002441 if (vm == NULL || p_env == NULL) {
2442 return JNI_ERR;
2443 }
Elliott Hughesf2682d52011-08-15 16:37:04 -07002444 JavaVMExt* raw_vm = reinterpret_cast<JavaVMExt*>(vm);
2445 Runtime* runtime = raw_vm->runtime;
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002446 const char* name = NULL;
2447 if (thr_args != NULL) {
2448 // TODO: check version
2449 name = static_cast<JavaVMAttachArgs*>(thr_args)->name;
2450 // TODO: thread group
2451 }
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002452 bool success = runtime->AttachCurrentThread(name, p_env);
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002453 if (!success) {
2454 return JNI_ERR;
2455 } else {
2456 return JNI_OK;
2457 }
2458}
2459
Elliott Hughesf2682d52011-08-15 16:37:04 -07002460jint DetachCurrentThread(JavaVM* vm) {
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002461 if (vm == NULL) {
2462 return JNI_ERR;
2463 } else {
Elliott Hughesf2682d52011-08-15 16:37:04 -07002464 JavaVMExt* raw_vm = reinterpret_cast<JavaVMExt*>(vm);
2465 Runtime* runtime = raw_vm->runtime;
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002466 runtime->DetachCurrentThread();
2467 return JNI_OK;
2468 }
2469}
2470
Elliott Hughesf2682d52011-08-15 16:37:04 -07002471jint GetEnv(JavaVM* vm, void** env, jint version) {
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002472 if (version < JNI_VERSION_1_1 || version > JNI_VERSION_1_6) {
2473 return JNI_EVERSION;
2474 }
2475 if (vm == NULL || env == NULL) {
2476 return JNI_ERR;
2477 }
2478 Thread* thread = Thread::Current();
2479 if (thread == NULL) {
2480 *env = NULL;
2481 return JNI_EDETACHED;
2482 }
2483 *env = thread->GetJniEnv();
2484 return JNI_OK;
2485}
2486
Elliott Hughesf2682d52011-08-15 16:37:04 -07002487jint AttachCurrentThreadAsDaemon(JavaVM* vm, JNIEnv** p_env, void* thr_args) {
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002488 if (vm == NULL || p_env == NULL) {
2489 return JNI_ERR;
2490 }
Elliott Hughesf2682d52011-08-15 16:37:04 -07002491 JavaVMExt* raw_vm = reinterpret_cast<JavaVMExt*>(vm);
2492 Runtime* runtime = raw_vm->runtime;
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002493 const char* name = NULL;
2494 if (thr_args != NULL) {
2495 // TODO: check version
2496 name = static_cast<JavaVMAttachArgs*>(thr_args)->name;
2497 // TODO: thread group
2498 }
Elliott Hughes40ef99e2011-08-11 17:44:34 -07002499 bool success = runtime->AttachCurrentThreadAsDaemon(name, p_env);
Carl Shapiro2ed144c2011-07-26 16:52:08 -07002500 if (!success) {
2501 return JNI_ERR;
2502 } else {
2503 return JNI_OK;
2504 }
2505}
2506
Elliott Hughesf2682d52011-08-15 16:37:04 -07002507struct JNIInvokeInterface gInvokeInterface = {
Carl Shapiroea4dca82011-08-01 13:45:38 -07002508 NULL, // reserved0
2509 NULL, // reserved1
2510 NULL, // reserved2
2511 DestroyJavaVM,
2512 AttachCurrentThread,
2513 DetachCurrentThread,
2514 GetEnv,
2515 AttachCurrentThreadAsDaemon
2516};
2517
Elliott Hughesbbd76712011-08-17 10:25:24 -07002518static const size_t kPinTableInitialSize = 16;
2519static const size_t kPinTableMaxSize = 1024;
2520
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002521static const size_t kGlobalsInitial = 512; // Arbitrary.
2522static const size_t kGlobalsMax = 51200; // Arbitrary sanity check.
2523
2524static const size_t kWeakGlobalsInitial = 16; // Arbitrary.
2525static const size_t kWeakGlobalsMax = 51200; // Arbitrary sanity check.
2526
Elliott Hughes0af55432011-08-17 18:37:28 -07002527JavaVMExt::JavaVMExt(Runtime* runtime, bool check_jni, bool verbose_jni)
Elliott Hughesbbd76712011-08-17 10:25:24 -07002528 : fns(&gInvokeInterface),
2529 runtime(runtime),
Elliott Hughes515a5bc2011-08-17 11:08:34 -07002530 check_jni(check_jni),
Elliott Hughes0af55432011-08-17 18:37:28 -07002531 verbose_jni(verbose_jni),
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002532 pin_table("pin table", kPinTableInitialSize, kPinTableMaxSize),
Elliott Hughesc5f7c912011-08-18 14:00:42 -07002533 globals_lock("JNI global reference table"),
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002534 globals(kGlobalsInitial, kGlobalsMax, kGlobal),
Elliott Hughesc5f7c912011-08-18 14:00:42 -07002535 weak_globals_lock("JNI weak global reference table"),
Elliott Hughes6c1a3942011-08-17 15:00:06 -07002536 weak_globals(kWeakGlobalsInitial, kWeakGlobalsMax, kWeakGlobal) {
Elliott Hughesf2682d52011-08-15 16:37:04 -07002537}
2538
Ian Rogersdf20fe02011-07-20 20:34:16 -07002539} // namespace art