Merge "Fix a bug, where one thread is using JNIEnv associated with another thread." into gingerbread

This commit is contained in:
Wei-Ta Chen
2010-08-19 00:28:10 -07:00
committed by Android (Google) Code Review
2 changed files with 22 additions and 9 deletions

View File

@@ -518,35 +518,48 @@ bool GraphicsJNI::setJavaPixelRef(JNIEnv* env, SkBitmap* bitmap,
///////////////////////////////////////////////////////////////////////////////
JavaPixelAllocator::JavaPixelAllocator(JNIEnv* env, bool reportSizeToVM)
: fEnv(env), fReportSizeToVM(reportSizeToVM) {}
: fReportSizeToVM(reportSizeToVM) {
if (env->GetJavaVM(&fVM) != JNI_OK) {
SkDebugf("------ [%p] env->GetJavaVM failed\n", env);
sk_throw();
}
}
bool JavaPixelAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) {
return GraphicsJNI::setJavaPixelRef(fEnv, bitmap, ctable, fReportSizeToVM);
JNIEnv* env = vm2env(fVM);
return GraphicsJNI::setJavaPixelRef(env, bitmap, ctable, fReportSizeToVM);
}
////////////////////////////////////////////////////////////////////////////////
JavaMemoryUsageReporter::JavaMemoryUsageReporter(JNIEnv* env)
: fEnv(env), fTotalSize(0) {}
: fTotalSize(0) {
if (env->GetJavaVM(&fVM) != JNI_OK) {
SkDebugf("------ [%p] env->GetJavaVM failed\n", env);
sk_throw();
}
}
JavaMemoryUsageReporter::~JavaMemoryUsageReporter() {
JNIEnv* env = vm2env(fVM);
jlong jtotalSize = fTotalSize;
fEnv->CallVoidMethod(gVMRuntime_singleton,
env->CallVoidMethod(gVMRuntime_singleton,
gVMRuntime_trackExternalFreeMethodID,
jtotalSize);
}
bool JavaMemoryUsageReporter::reportMemory(size_t memorySize) {
jlong jsize = memorySize; // the VM wants longs for the size
bool r = fEnv->CallBooleanMethod(gVMRuntime_singleton,
JNIEnv* env = vm2env(fVM);
bool r = env->CallBooleanMethod(gVMRuntime_singleton,
gVMRuntime_trackExternalAllocationMethodID,
jsize);
if (GraphicsJNI::hasException(fEnv)) {
if (GraphicsJNI::hasException(env)) {
return false;
}
if (!r) {
LOGE("VM won't let us allocate %zd bytes\n", memorySize);
doThrowOOME(fEnv, "bitmap size exceeds VM budget");
doThrowOOME(env, "bitmap size exceeds VM budget");
return false;
}
fTotalSize += memorySize;

View File

@@ -80,7 +80,7 @@ public:
virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable);
private:
JNIEnv* fEnv;
JavaVM* fVM;
bool fReportSizeToVM;
};
@@ -92,7 +92,7 @@ public:
virtual bool reportMemory(size_t memorySize);
private:
JNIEnv* fEnv;
JavaVM* fVM;
size_t fTotalSize;
};