Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9f7257f0 authored by Wei-Ta Chen's avatar Wei-Ta Chen Committed by Android Git Automerger
Browse files

am 8d124f70: Merge "Fix a bug, where one thread is using JNIEnv associated...

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

Merge commit '8d124f70' into gingerbread-plus-aosp

* commit '8d124f70':
  Fix a bug, where one thread is using JNIEnv associated with another thread.
parents e1879085 8d124f70
Loading
Loading
Loading
Loading
+20 −7
Original line number Diff line number Diff line
@@ -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;
+2 −2
Original line number Diff line number Diff line
@@ -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;
};