diff --git a/src/third_party/jni_zero/BUILD.gn b/src/third_party/jni_zero/BUILD.gn index 58e0233e52..b48cf2df07 100644 --- a/src/third_party/jni_zero/BUILD.gn +++ b/src/third_party/jni_zero/BUILD.gn @@ -8,49 +8,6 @@ config("jni_include_dir") { include_dirs = [ jni_headers_dir ] } -generate_jni("generate_jni") { - sources = [ - "java/src/org/jni_zero/CommonApis.java", - "java/src/org/jni_zero/JniZero.java", - ] - visibility = [ - ":*", - "//components/cronet/android/*", - ] -} - -# Common classes to save projects from having to generate them. -# Do not remove from this list without checking that no clients -# use what you are removing. -generate_jar_jni("system_jni") { - classes = [ - "android/os/Process.class", - "java/lang/Boolean.class", - "java/lang/Integer.class", - "java/lang/Float.class", - "java/lang/Double.class", - "java/lang/Long.class", - "java/lang/Object.class", - "java/lang/Runnable.class", - "java/lang/Runtime.class", - "java/lang/Throwable.class", - "java/util/Arrays.class", - "java/util/Collection.class", - "java/util/List.class", - "java/util/Map.class", - ] - visibility = [ ":*" ] -} - -generate_jar_jni("system_jni_unchecked_exceptions") { - classes = [ - "java/lang/ClassLoader.class", - "java/nio/ByteBuffer.class", - ] - visibility = [ ":*" ] - unchecked_exceptions = true -} - # This is the public target that we intend others to use. component("jni_zero") { public = [ @@ -60,7 +17,7 @@ component("jni_zero") { ] sources = [ - "common_apis.cc", + "common_apis.h", "default_conversions.cc", "java_refs.cc", "java_refs.h", @@ -96,14 +53,9 @@ component("jni_zero") { public_configs = [ "//third_party/jdk:jdk" ] } - deps = [ ":generate_jni($default_toolchain)" ] - if (build_with_chromium) { - deps += [ "//base:base_static" ] - } - public_deps = [ - ":system_jni($default_toolchain)", - ":system_jni_unchecked_exceptions($default_toolchain)", + deps = [ ] + public_deps = [] } if (enable_java_templates && is_android) { diff --git a/src/third_party/jni_zero/jni_zero.cc b/src/third_party/jni_zero/jni_zero.cc index 29b021b995..fc83e75c59 100644 --- a/src/third_party/jni_zero/jni_zero.cc +++ b/src/third_party/jni_zero/jni_zero.cc @@ -9,11 +9,9 @@ #include #include -#include "third_party/jni_zero/generate_jni/JniZero_jni.h" #include "third_party/jni_zero/jni_methods.h" #include "third_party/jni_zero/jni_zero_internal.h" #include "third_party/jni_zero/logging.h" -#include "third_party/jni_zero/system_jni_unchecked_exceptions/ClassLoader_jni.h" #ifdef UNSAFE_BUFFERS_BUILD // TODO(crbug.com/393091624): Remove this and convert code to safer constructs. @@ -52,16 +50,8 @@ JavaVM* g_jvm = nullptr; jclass (*g_class_resolver)(JNIEnv*, const char*) = nullptr; -LeakedJavaGlobalRef g_class_loader = nullptr; - void (*g_exception_handler_callback)(JNIEnv*) = nullptr; -jclass DefaultClassResolver(JNIEnv* env, const char* class_name) { - JNI_ZERO_DCHECK(g_class_loader); - auto j_class_name = jni_zero::AdoptRef(env, env->NewStringUTF(class_name)); - return g_class_loader->loadClass(env, j_class_name).Release(); -} - jclass GetClassInternal(JNIEnv* env, const char* class_name) { if (g_class_resolver != nullptr) { return g_class_resolver(env, class_name); @@ -84,10 +74,6 @@ jclass GetClassInternal(JNIEnv* env, const char* class_name) { return env->FindClass(slash_name); } -jclass GetClassGlobalRef(JNIEnv* env, jobject obj) { - return static_cast(env->NewGlobalRef(env->GetObjectClass(obj))); -} - } // namespace void JNI_JniZero_SetJniClassLoader( @@ -162,38 +148,6 @@ void InitVM(JavaVM* vm) { return; } g_jvm = vm; - JNIEnv* env = AttachCurrentThread(); -#if defined(JNI_ZERO_MULTIPLEXING_ENABLED) - JniZeroJni::crashIfMultiplexingMisaligned(env, kJniZeroHashWhole, - kJniZeroHashPriority); -#else - // Mark as used when multiplexing not enabled. - (void)&Java_JniZero_crashIfMultiplexingMisaligned; -#endif - ScopedJavaLocalRef> globals = JniZeroJni::init(env); - jobject empty_list = env->GetObjectArrayElement(globals.obj(), 0); - jobject empty_map = env->GetObjectArrayElement(globals.obj(), 1); - jobject jni_class_loader = env->GetObjectArrayElement(globals.obj(), 2); - - // Leak a few local refs since JNI will clean them up for us anyways. - g_empty_list.Reset(env, CreateLeaky(env, empty_list)); - g_empty_map.Reset(env, CreateLeaky(env, empty_map)); - g_empty_string.Reset(env, CreateLeaky(env, env->NewString(nullptr, 0))); - - g_string_class = GetClassGlobalRef(env, g_empty_string.obj()); - g_class_loader_class = GetClassGlobalRef(env, jni_class_loader); - g_object_class = static_cast( - env->NewGlobalRef(env->GetSuperclass(g_string_class))); - - if (!g_class_resolver) { - // Use ClassLoader.loadClass() rather than env->FindClass() because - // env->FindClass() uses the bootstrap classloader for threads created by - // native code (which leads to classes not being able to be found). - if (!g_class_loader) { - g_class_loader.Reset(env, CreateLeaky(env, jni_class_loader)); - } - g_class_resolver = &DefaultClassResolver; - } } void DisableJvmForTesting() { @@ -243,7 +197,6 @@ void SetClassResolver(jclass (*resolver)(JNIEnv*, const char*)) { void SetClassLoader(JNIEnv* env, const JavaRef& class_loader) { JNI_ZERO_DCHECK(class_loader); - g_class_loader.Reset(env, class_loader); } ScopedJavaLocalRef GetClass(JNIEnv* env, const char* class_name) { diff --git a/src/third_party/jni_zero/jni_zero.h b/src/third_party/jni_zero/jni_zero.h index dab860bb1c..cbe64286bc 100644 --- a/src/third_party/jni_zero/jni_zero.h +++ b/src/third_party/jni_zero/jni_zero.h @@ -17,7 +17,7 @@ #include "third_party/jni_zero/type_conversions.h" // IWYU pragma: end_exports -#define DEFINE_JNI(className) DEFINE_JNI_FOR_##className() +#define DEFINE_JNI(className) namespace jni_zero {