From 24ce5fb2cc09d0a14406e7b935f8648c5720d27e Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 8 Apr 2011 20:01:01 -0700 Subject: Kill the global references in the OpenGL wrappers. Just use jniThrowException instead. Note that it would be trivial to throw seemingly more appropriate exceptions (NullPointerException and OutOfMemoryException in particular), but I'm only attempting to preserve existing behavior here. I also found shadowing bugs in some of the special-case functions, which would previously always have leaked memory. This also moves an accidental change to a generated file (ActivityThread -> AppGlobals) into the generator, so it won't be overwritten in future. Change-Id: Iab570310b568cb406c60dd0e2b8211f8a36ae590 --- core/jni/android_opengl_GLES10Ext.cpp | 65 +++++++++++------------------------ 1 file changed, 21 insertions(+), 44 deletions(-) (limited to 'core/jni/android_opengl_GLES10Ext.cpp') diff --git a/core/jni/android_opengl_GLES10Ext.cpp b/core/jni/android_opengl_GLES10Ext.cpp index f17ef21..1154cef 100644 --- a/core/jni/android_opengl_GLES10Ext.cpp +++ b/core/jni/android_opengl_GLES10Ext.cpp @@ -2,21 +2,23 @@ ** ** Copyright 2009, The Android Open Source Project ** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at ** -** http://www.apache.org/licenses/LICENSE-2.0 +** http://www.apache.org/licenses/LICENSE-2.0 ** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and ** limitations under the License. */ // This source file is automatically generated +#include "jni.h" +#include "JNIHelp.h" #include #include @@ -28,10 +30,6 @@ static int initialized = 0; static jclass nioAccessClass; static jclass bufferClass; -static jclass OOMEClass; -static jclass UOEClass; -static jclass IAEClass; -static jclass AIOOBEClass; static jmethodID getBasePointerID; static jmethodID getBaseArrayID; static jmethodID getBaseArrayOffsetID; @@ -42,7 +40,7 @@ static jfieldID elementSizeShiftID; /* Cache method IDs each time the class is loaded. */ static void -nativeClassInitBuffer(JNIEnv *_env) +nativeClassInit(JNIEnv *_env, jclass glImplClass) { jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); @@ -64,26 +62,6 @@ nativeClassInitBuffer(JNIEnv *_env) } -static void -nativeClassInit(JNIEnv *_env, jclass glImplClass) -{ - nativeClassInitBuffer(_env); - - jclass IAEClassLocal = - _env->FindClass("java/lang/IllegalArgumentException"); - jclass OOMEClassLocal = - _env->FindClass("java/lang/OutOfMemoryError"); - jclass UOEClassLocal = - _env->FindClass("java/lang/UnsupportedOperationException"); - jclass AIOOBEClassLocal = - _env->FindClass("java/lang/ArrayIndexOutOfBoundsException"); - - IAEClass = (jclass) _env->NewGlobalRef(IAEClassLocal); - OOMEClass = (jclass) _env->NewGlobalRef(OOMEClassLocal); - UOEClass = (jclass) _env->NewGlobalRef(UOEClassLocal); - AIOOBEClass = (jclass) _env->NewGlobalRef(AIOOBEClassLocal); -} - static void * getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining) { @@ -104,13 +82,13 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining) *array = NULL; return (void *) (jint) pointer; } - + *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass, getBaseArrayID, buffer); offset = _env->CallStaticIntMethod(nioAccessClass, getBaseArrayOffsetID, buffer); data = _env->GetPrimitiveArrayCritical(*array, (jboolean *) 0); - + return (void *) ((char *) data + offset); } @@ -123,7 +101,6 @@ releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit) } // -------------------------------------------------------------------------- - /* GLbitfield glQueryMatrixxOES ( GLfixed *mantissa, GLint *exponent ) */ static jint android_glQueryMatrixxOES___3II_3II @@ -139,18 +116,18 @@ android_glQueryMatrixxOES___3II_3II if (!mantissa_ref) { _exception = 1; - _env->ThrowNew(IAEClass, "mantissa == null"); + jniThrowException(_env, "java/lang/IllegalArgumentException", "mantissa == null"); goto exit; } if (mantissaOffset < 0) { _exception = 1; - _env->ThrowNew(IAEClass, "mantissaOffset < 0"); + jniThrowException(_env, "java/lang/IllegalArgumentException", "mantissaOffset < 0"); goto exit; } _mantissaRemaining = _env->GetArrayLength(mantissa_ref) - mantissaOffset; if (_mantissaRemaining < 16) { _exception = 1; - _env->ThrowNew(IAEClass, "length - mantissaOffset < 16"); + jniThrowException(_env, "java/lang/IllegalArgumentException", "length - mantissaOffset < 16"); goto exit; } mantissa_base = (GLfixed *) @@ -159,18 +136,18 @@ android_glQueryMatrixxOES___3II_3II if (!exponent_ref) { _exception = 1; - _env->ThrowNew(IAEClass, "exponent == null"); + jniThrowException(_env, "java/lang/IllegalArgumentException", "exponent == null"); goto exit; } if (exponentOffset < 0) { _exception = 1; - _env->ThrowNew(IAEClass, "exponentOffset < 0"); + jniThrowException(_env, "java/lang/IllegalArgumentException", "exponentOffset < 0"); goto exit; } _exponentRemaining = _env->GetArrayLength(exponent_ref) - exponentOffset; if (_exponentRemaining < 16) { _exception = 1; - _env->ThrowNew(IAEClass, "length - exponentOffset < 16"); + jniThrowException(_env, "java/lang/IllegalArgumentException", "length - exponentOffset < 16"); goto exit; } exponent_base = (GLint *) @@ -210,13 +187,13 @@ android_glQueryMatrixxOES__Ljava_nio_IntBuffer_2Ljava_nio_IntBuffer_2 mantissa = (GLfixed *)getPointer(_env, mantissa_buf, &_mantissaArray, &_mantissaRemaining); if (_mantissaRemaining < 16) { _exception = 1; - _env->ThrowNew(IAEClass, "remaining() < 16"); + jniThrowException(_env, "java/lang/IllegalArgumentException", "remaining() < 16"); goto exit; } exponent = (GLint *)getPointer(_env, exponent_buf, &_exponentArray, &_exponentRemaining); if (_exponentRemaining < 16) { _exception = 1; - _env->ThrowNew(IAEClass, "remaining() < 16"); + jniThrowException(_env, "java/lang/IllegalArgumentException", "remaining() < 16"); goto exit; } _returnValue = glQueryMatrixxOES( -- cgit v1.1