1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-27 20:41:58 +03:00

Minor internal cleanups and additional test metrics.

FossilOrigin-Name: fa0a6b6e8e6c711585bca30357e465f7a2f08a1c7159ecf23031af1e5158b89d
This commit is contained in:
stephan
2023-08-07 00:29:38 +00:00
parent 8af781fc4d
commit 005baf67d5
6 changed files with 61 additions and 32 deletions

View File

@ -1103,6 +1103,7 @@ static PerDbStateJni * PerDbStateJni_alloc(JNIEnv * const env, sqlite3 *pDb,
return rv; return rv;
} }
#if 0
static void PerDbStateJni_dump(PerDbStateJni *s){ static void PerDbStateJni_dump(PerDbStateJni *s){
MARKER(("PerDbStateJni->env @ %p\n", s->env)); MARKER(("PerDbStateJni->env @ %p\n", s->env));
MARKER(("PerDbStateJni->pDb @ %p\n", s->pDb)); MARKER(("PerDbStateJni->pDb @ %p\n", s->pDb));
@ -1113,6 +1114,7 @@ static void PerDbStateJni_dump(PerDbStateJni *s){
MARKER(("PerDbStateJni->busyHandler.jObj @ %p\n", s->busyHandler.jObj)); MARKER(("PerDbStateJni->busyHandler.jObj @ %p\n", s->busyHandler.jObj));
MARKER(("PerDbStateJni->env @ %p\n", s->env)); MARKER(("PerDbStateJni->env @ %p\n", s->env));
} }
#endif
/** /**
Returns the PerDbStateJni object for the given db. If allocIfNeeded is Returns the PerDbStateJni object for the given db. If allocIfNeeded is
@ -1554,7 +1556,8 @@ typedef void (*udf_xFinal_f)(sqlite3_context*);
/** /**
State for binding Java-side UDFs. State for binding Java-side UDFs.
*/ */
typedef struct { typedef struct UDFState UDFState;
struct UDFState {
JNIEnv * env; /* env registered from */; JNIEnv * env; /* env registered from */;
jobject jObj /* SQLFunction instance */; jobject jObj /* SQLFunction instance */;
jclass klazz /* jObj's class */; jclass klazz /* jObj's class */;
@ -1566,7 +1569,7 @@ typedef struct {
jmethodID jmidxFinal; jmethodID jmidxFinal;
jmethodID jmidxValue; jmethodID jmidxValue;
jmethodID jmidxInverse; jmethodID jmidxInverse;
} UDFState; };
static UDFState * UDFState_alloc(JNIEnv * const env, jobject jObj){ static UDFState * UDFState_alloc(JNIEnv * const env, jobject jObj){
UDFState * const s = sqlite3_malloc(sizeof(UDFState)); UDFState * const s = sqlite3_malloc(sizeof(UDFState));
@ -2019,18 +2022,13 @@ static jint s3jni_close_db(JNIEnv * const env, jobject jDb, int version){
int rc = 0; int rc = 0;
PerDbStateJni * ps = 0; PerDbStateJni * ps = 0;
assert(version == 1 || version == 2); assert(version == 1 || version == 2);
if(0){
PerDbStateJni * s = S3Global.perDb.aUsed;
for( ; s; s = s->pNext){
PerDbStateJni_dump(s);
}
}
ps = PerDbStateJni_for_db(env, jDb, 0, 0); ps = PerDbStateJni_for_db(env, jDb, 0, 0);
if(!ps) return rc; if(ps){
rc = 1==version ? (jint)sqlite3_close(ps->pDb) : (jint)sqlite3_close_v2(ps->pDb); rc = 1==version ? (jint)sqlite3_close(ps->pDb) : (jint)sqlite3_close_v2(ps->pDb);
if(ps) PerDbStateJni_set_aside(ps) PerDbStateJni_set_aside(ps)
/* MUST come after close() because of ps->trace. */; /* MUST come after close() because of ps->trace. */;
NativePointerHolder_set(env, jDb, 0, S3ClassNames.sqlite3); NativePointerHolder_set(env, jDb, 0, S3ClassNames.sqlite3);
}
return (jint)rc; return (jint)rc;
} }
@ -2053,15 +2051,18 @@ static unsigned int s3jni_utf16_strlen(void const * z){
return i; return i;
} }
/**
sqlite3_collation_needed16() hook impl.
*/
static void s3jni_collation_needed_impl16(void *pState, sqlite3 *pDb, static void s3jni_collation_needed_impl16(void *pState, sqlite3 *pDb,
int eTextRep, const void * z16Name){ int eTextRep, const void * z16Name){
PerDbStateJni * const ps = pState; PerDbStateJni * const ps = pState;
JNIEnv * const env = ps->env; JNIEnv * const env = ps->env;
unsigned int const nName = s3jni_utf16_strlen(z16Name); unsigned int const nName = s3jni_utf16_strlen(z16Name);
jstring jName; jstring jName = (*env)->NewString(env, (jchar const *)z16Name, nName);
jName = (*env)->NewString(env, (jchar const *)z16Name, nName); IFTHREW{
IFTHREW {
s3jni_db_error(ps->pDb, SQLITE_NOMEM, 0); s3jni_db_error(ps->pDb, SQLITE_NOMEM, 0);
EXCEPTION_CLEAR;
}else{ }else{
(*env)->CallVoidMethod(env, ps->collationNeeded.jObj, (*env)->CallVoidMethod(env, ps->collationNeeded.jObj,
ps->collationNeeded.midCallback, ps->collationNeeded.midCallback,
@ -2082,7 +2083,8 @@ JDECL(jint,1collation_1needed)(JENV_CSELF, jobject jDb, jobject jHook){
jmethodID xCallback; jmethodID xCallback;
JniHookState * const pHook = &ps->collationNeeded; JniHookState * const pHook = &ps->collationNeeded;
int rc; int rc;
if(!ps) return SQLITE_MISUSE;
if( !ps ) return SQLITE_MISUSE;
pOld = pHook->jObj; pOld = pHook->jObj;
if(pOld && jHook && if(pOld && jHook &&
(*env)->IsSameObject(env, pOld, jHook)){ (*env)->IsSameObject(env, pOld, jHook)){
@ -3291,13 +3293,15 @@ JDECL(void,1do_1something_1for_1developer)(JENV_CSELF){
puts("sizeofs:"); puts("sizeofs:");
#define SO(T) printf("\tsizeof(" #T ") = %u\n", (unsigned)sizeof(T)) #define SO(T) printf("\tsizeof(" #T ") = %u\n", (unsigned)sizeof(T))
SO(void*); SO(void*);
SO(JniHookState);
SO(JNIEnvCache); SO(JNIEnvCache);
SO(JniHookState);
SO(PerDbStateJni); SO(PerDbStateJni);
SO(S3Global);
SO(S3ClassNames); SO(S3ClassNames);
printf("\t(^^^ %u NativePointerHolder subclasses)\n", printf("\t(^^^ %u NativePointerHolder subclasses)\n",
(unsigned)(sizeof(S3ClassNames) / sizeof(const char *))); (unsigned)(sizeof(S3ClassNames) / sizeof(const char *)));
SO(S3Global);
SO(S3JniAutoExtension);
SO(UDFState);
printf("Cache info:\n"); printf("Cache info:\n");
printf("\tNativePointerHolder cache: %u misses, %u hits\n", printf("\tNativePointerHolder cache: %u misses, %u hits\n",
S3Global.metrics.nphCacheMisses, S3Global.metrics.nphCacheMisses,

View File

@ -21,9 +21,9 @@ public interface AutoExtension {
Must function as described for the sqlite3_auto_extension(), Must function as described for the sqlite3_auto_extension(),
with the caveat that the signature is more limited. with the caveat that the signature is more limited.
As an exception to the callbacks-must-not-throw rule, As an exception (as it were) to the callbacks-must-not-throw
AutoExtensions may do so and the exception's error rule, AutoExtensions may do so and the exception's error message
message will be set as the db's error string. will be set as the db's error string.
*/ */
int xEntryPoint(sqlite3 db); int xEntryPoint(sqlite3 db);
} }

View File

@ -475,6 +475,11 @@ public final class SQLite3Jni {
heed. Passing the object to sqlite3_close() or sqlite3_close_v2() heed. Passing the object to sqlite3_close() or sqlite3_close_v2()
will clear that pointer mapping. will clear that pointer mapping.
Recall that even if opening fails, the output pointer might be
non-null. Any error message about the failure will be in that
object and it is up to the caller to sqlite3_close() that
db handle.
Pedantic note: though any number of Java-level sqlite3 objects Pedantic note: though any number of Java-level sqlite3 objects
may refer to/wrap a single C-level (sqlite3*), the JNI internals may refer to/wrap a single C-level (sqlite3*), the JNI internals
take a reference to the object which is passed to sqlite3_open() take a reference to the object which is passed to sqlite3_open()

View File

@ -1076,6 +1076,26 @@ public class Tester1 {
outln("Tests done. Metrics:"); outln("Tests done. Metrics:");
outln("\tAssertions checked: "+affirmCount); outln("\tAssertions checked: "+affirmCount);
outln("\tDatabases opened: "+metrics.dbOpen); outln("\tDatabases opened: "+metrics.dbOpen);
int nMethods = 0;
int nNatives = 0;
final java.lang.reflect.Method[] declaredMethods =
SQLite3Jni.class.getDeclaredMethods();
for(java.lang.reflect.Method m : declaredMethods){
int mod = m.getModifiers();
if( 0!=(mod & java.lang.reflect.Modifier.STATIC) ){
final String name = m.getName();
if(name.startsWith("sqlite3_")){
++nMethods;
if( 0!=(mod & java.lang.reflect.Modifier.NATIVE) ){
++nNatives;
}
}
}
}
outln("\tSQLite3Jni sqlite3_*() methods: "+
nNatives+" native methods and "+
(nMethods - nNatives)+" Java impls");
outln("\tTotal time = " outln("\tTotal time = "
+((timeEnd - timeStart)/1000000.0)+"ms"); +((timeEnd - timeStart)/1000000.0)+"ms");
} }

View File

@ -1,5 +1,5 @@
C Bind\sthe\sauto-extension\sAPIs\sto\sJNI. C Minor\sinternal\scleanups\sand\sadditional\stest\smetrics.
D 2023-08-07T00:06:31.250 D 2023-08-07T00:29:38.785
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -232,10 +232,10 @@ F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282
F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8
F ext/jni/GNUmakefile 61d9bbc179a49523a142928455b3297779b9c40f25783ecf1538279e426cbc99 F ext/jni/GNUmakefile 61d9bbc179a49523a142928455b3297779b9c40f25783ecf1538279e426cbc99
F ext/jni/README.md e965674505e105626127ad45e628e4d19fcd379cdafc4d23c814c1ac2c55681d F ext/jni/README.md e965674505e105626127ad45e628e4d19fcd379cdafc4d23c814c1ac2c55681d
F ext/jni/src/c/sqlite3-jni.c 406f3fe36661b3628d108a912246b48cafd7fcc1f8b30a563ce6806addb30d71 F ext/jni/src/c/sqlite3-jni.c a59464adb77c0d2c539483b4d09b8c547dc97c73cf7f26b4934602c8cd4da28d
F ext/jni/src/c/sqlite3-jni.h 68d219dd351676e819deb38926ebcee0fda141403ce4efa60c3d8bd77993d220 F ext/jni/src/c/sqlite3-jni.h 68d219dd351676e819deb38926ebcee0fda141403ce4efa60c3d8bd77993d220
F ext/jni/src/org/sqlite/jni/Authorizer.java 1308988f7f40579ea0e4deeaec3c6be971630566bd021c31367fe3f5140db892 F ext/jni/src/org/sqlite/jni/Authorizer.java 1308988f7f40579ea0e4deeaec3c6be971630566bd021c31367fe3f5140db892
F ext/jni/src/org/sqlite/jni/AutoExtension.java aac84ec21c93306ff5c6ff3b0130de5b76f265dfbc8f7cd158d62cfb8384ff57 F ext/jni/src/org/sqlite/jni/AutoExtension.java 3409ad8954d6466bf772e6be9379e0e337312b446b668287062845755a16844d
F ext/jni/src/org/sqlite/jni/BusyHandler.java 1b1d3e5c86cd796a0580c81b6af6550ad943baa25e47ada0dcca3aff3ebe978c F ext/jni/src/org/sqlite/jni/BusyHandler.java 1b1d3e5c86cd796a0580c81b6af6550ad943baa25e47ada0dcca3aff3ebe978c
F ext/jni/src/org/sqlite/jni/Collation.java 8dffbb00938007ad0967b2ab424d3c908413af1bbd3d212b9c9899910f1218d1 F ext/jni/src/org/sqlite/jni/Collation.java 8dffbb00938007ad0967b2ab424d3c908413af1bbd3d212b9c9899910f1218d1
F ext/jni/src/org/sqlite/jni/CollationNeeded.java ebc7cd96d46a70daa76016a308e80f70a3f21d3282787c8d139aa840fdcb1bd7 F ext/jni/src/org/sqlite/jni/CollationNeeded.java ebc7cd96d46a70daa76016a308e80f70a3f21d3282787c8d139aa840fdcb1bd7
@ -251,8 +251,8 @@ F ext/jni/src/org/sqlite/jni/OutputPointer.java 053ea7dbc1234dd70b8948009a52a3f1
F ext/jni/src/org/sqlite/jni/ProgressHandler.java 5979450e996416d28543f1d42634d308439565a99332a8bd84e424af667116cc F ext/jni/src/org/sqlite/jni/ProgressHandler.java 5979450e996416d28543f1d42634d308439565a99332a8bd84e424af667116cc
F ext/jni/src/org/sqlite/jni/RollbackHook.java b04c8abcc6ade44a8a57129e33765793f69df0ba909e49ba18d73f4268d92564 F ext/jni/src/org/sqlite/jni/RollbackHook.java b04c8abcc6ade44a8a57129e33765793f69df0ba909e49ba18d73f4268d92564
F ext/jni/src/org/sqlite/jni/SQLFunction.java 09ce81c1c637e31c3a830d4c859cce95d65f5e02ff45f8bd1985b3479381bc46 F ext/jni/src/org/sqlite/jni/SQLFunction.java 09ce81c1c637e31c3a830d4c859cce95d65f5e02ff45f8bd1985b3479381bc46
F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 9af0e0ea79db59d5c4dac13f70031dd5069223d8198f7324f8c1c25e60451e8c F ext/jni/src/org/sqlite/jni/SQLite3Jni.java e43d17ef7601d6294fa5ba7e15a2be2bcb819b41f4fe0ac069ce45e324b5a928
F ext/jni/src/org/sqlite/jni/Tester1.java 63fc2f58b3a5abdad8bd41ff4a1b2572c24fa9246c17a3fcab07dc6adf06ff35 F ext/jni/src/org/sqlite/jni/Tester1.java 762c866e3c401f8de2551e8bdc5252f5943693fe6bbbace82c3af984c190a0fd
F ext/jni/src/org/sqlite/jni/TesterFts5.java cf2d687baafffdeba219b77cf611fd47a0556248820ea794ae3e8259bfbdc5ee F ext/jni/src/org/sqlite/jni/TesterFts5.java cf2d687baafffdeba219b77cf611fd47a0556248820ea794ae3e8259bfbdc5ee
F ext/jni/src/org/sqlite/jni/Tracer.java a5cece9f947b0af27669b8baec300b6dd7ff859c3e6a6e4a1bd8b50f9714775d F ext/jni/src/org/sqlite/jni/Tracer.java a5cece9f947b0af27669b8baec300b6dd7ff859c3e6a6e4a1bd8b50f9714775d
F ext/jni/src/org/sqlite/jni/UpdateHook.java e58645a1727f8a9bbe72dc072ec5b40d9f9362cb0aa24acfe93f49ff56a9016d F ext/jni/src/org/sqlite/jni/UpdateHook.java e58645a1727f8a9bbe72dc072ec5b40d9f9362cb0aa24acfe93f49ff56a9016d
@ -2083,8 +2083,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 34da294ab558880e81eebd7d261bc590551d5a7d2855e844695cef6394647ea7 P 746a5fa079ad80b3c59411202ee601e0b5c50e79e5994d5e464fa06d3c276324
R 8af70828073a693d0f965376a6f73a57 R 07d630346a076501319c1423eea49390
U stephan U stephan
Z 18db46b387e0d752e217b2db93c72ada Z bdddfbdfa46e3004c7cc7a21bdb63878
# Remove this line to create a well-formed Fossil manifest. # Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
746a5fa079ad80b3c59411202ee601e0b5c50e79e5994d5e464fa06d3c276324 fa0a6b6e8e6c711585bca30357e465f7a2f08a1c7159ecf23031af1e5158b89d