globals.c
来自「This is a resource based on j2me embedde」· C语言 代码 · 共 1,369 行 · 第 1/3 页
C
1,369 行
/* * Copyright 1990-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. * */#include "javavm/include/defs.h"#include "javavm/include/objects.h"#include "javavm/include/classes.h"#include "javavm/include/sync.h"#include "javavm/include/globals.h"#include "javavm/include/interpreter.h"#include "javavm/include/preloader.h"#include "javavm/include/globalroots.h"#include "javavm/include/directmem.h"#include "javavm/include/indirectmem.h"#include "javavm/include/stackmaps.h"#include "javavm/include/utils.h"#include "javavm/include/timestamp.h"#ifndef CDC_10#include "javavm/include/javaAssertions.h"#endif#include "jni_statics.h"#include "native/java/util/zip/zip_util.h"#include "javavm/include/typeid.h"#include "javavm/include/string.h"#include "javavm/include/gc/gc_impl.h"#include "javavm/include/clib.h"#include "javavm/include/porting/memory.h"#ifdef CVM_JVMTI#include "javavm/include/jvmti_jni.h"#include "javavm/include/porting/time.h"#endif#ifdef CVM_JVMPI#include "javavm/include/jvmpi_impl.h"#endif#ifdef CVM_JIT#include "javavm/include/jit_common.h"#endif#ifdef CVM_DYNAMIC_LINKING#include "javavm/include/porting/linker.h"#endif/* * VM global state */CVMGlobalState CVMglobals;/* * JNI natives and utilities global state */CVMJNIStatics CVMjniGlobalStatics;/* * Target specific global state, exported to the HPI */CVMTargetGlobalState * const CVMtargetGlobals = &CVMglobals.target;#ifdef CVMJIT_TRAP_BASED_GC_CHECKS/* Pointer to CVMglobals.jit.gcTrapAddr so asm code can easily locate it */void** const CVMgcTrapAddrPtr = (void**)&CVMglobals.jit.gcTrapAddr;#endif#ifdef CVM_AOT/* Pointer to CVMglobals.jit.codeCacheAOTStart */void** const CVMJITcodeCacheAOTStart = (void**)&CVMglobals.jit.codeCacheAOTStart;/* Pointer to CVMglobals.jit.codeCacheAOTEnd */void** const CVMJITcodeCacheAOTEnd = (void**)&CVMglobals.jit.codeCacheAOTEnd;#endif#ifdef CVM_JIT/* Pointer to CVMglobals.jit.codeCacheDecompileStart */void** const CVMJITcodeCacheDecompileStart = (void**)&CVMglobals.jit.codeCacheDecompileStart;#endif/* * Capacities for the class table of dynamcially loaded classes. * NOTE: these values also used for the class global roots stack. */#define CVM_MIN_CLASSTABLE_STACKCHUNK_SIZE 500#define CVM_MAX_CLASSTABLE_STACK_SIZE 20000#define CVM_INITIAL_CLASSTABLE_STACK_SIZE 500/* * Capacities for the global roots stack. It holds both regular global * roots and jni global refs. */#define CVM_MIN_GLOBALROOTS_STACKCHUNK_SIZE 500#define CVM_MAX_GLOBALROOTS_STACK_SIZE \ 100 * CVM_MIN_GLOBALROOTS_STACKCHUNK_SIZE#define CVM_INITIAL_GLOBALROOTS_STACK_SIZE \ CVM_MIN_GLOBALROOTS_STACKCHUNK_SIZE/* * Capacities for the JNI weak global refs stack. */#define CVM_MIN_WEAK_GLOBALROOTS_STACKCHUNK_SIZE \ CVM_MIN_GLOBALROOTS_STACKCHUNK_SIZE#ifdef CVM_JVMTI#define CVM_MAX_WEAK_GLOBALROOTS_STACK_SIZE \ CVM_MAX_GLOBALROOTS_STACK_SIZE * 4#else#define CVM_MAX_WEAK_GLOBALROOTS_STACK_SIZE \ CVM_MAX_GLOBALROOTS_STACK_SIZE#endif#define CVM_INITIAL_WEAK_GLOBALROOTS_STACK_SIZE \ CVM_INITIAL_GLOBALROOTS_STACK_SIZE/* * Capacities for the Class global roots stack. */#define CVM_MIN_CLASS_GLOBALROOTS_STACKCHUNK_SIZE \ CVM_MIN_CLASSTABLE_STACKCHUNK_SIZE#define CVM_MAX_CLASS_GLOBALROOTS_STACK_SIZE \ CVM_MAX_CLASSTABLE_STACK_SIZE#define CVM_INITIAL_CLASS_GLOBALROOTS_STACK_SIZE \ CVM_INITIAL_CLASSTABLE_STACK_SIZE/* * Capacities for the ClassLoader global roots stack. */#define CVM_MIN_CLASSLOADER_GLOBALROOTS_STACKCHUNK_SIZE 30#define CVM_MAX_CLASSLOADER_GLOBALROOTS_STACK_SIZE \ 10 * CVM_MIN_CLASS_GLOBALROOTS_STACKCHUNK_SIZE#define CVM_INITIAL_CLASSLOADER_GLOBALROOTS_STACK_SIZE \ CVM_MIN_CLASS_GLOBALROOTS_STACKCHUNK_SIZE/* * Capacities for the ProtectionDomain global roots stack. */#define CVM_MIN_PROTECTION_DOMAIN_GLOBALROOTS_STACKCHUNK_SIZE \ CVM_MIN_CLASSTABLE_STACKCHUNK_SIZE#define CVM_MAX_PROTECTION_DOMAIN_GLOBALROOTS_STACK_SIZE \ CVM_MAX_CLASSTABLE_STACK_SIZE#define CVM_INITIAL_PROTECTION_DOMAIN_GLOBALROOTS_STACK_SIZE \ CVM_INITIAL_CLASSTABLE_STACK_SIZEstatic void CVMinitJNIStatics(){ memset((void*)&CVMjniGlobalStatics, 0, sizeof(CVMJNIStatics));}static void CVMdestroyJNIStatics(){ /* Nothing to do */}/* * The table of global sys mutexes so we can easily init, destroy, lock, * and unlock all of them. */typedef struct { CVMSysMutex* mutex; const char* name;} CVMGlobalSysMutexEntry;#define CVM_SYSMUTEX_ENTRY(mutex, name) {&CVMglobals.mutex, name}static const CVMGlobalSysMutexEntry globalSysMutexes[] = {#ifdef CVM_CLASSLOADING CVM_SYSMUTEX_ENTRY(nullClassLoaderLock, "NULL classloader lock"),#endif#ifdef CVM_JIT CVM_SYSMUTEX_ENTRY(jitLock, "jit lock"),#endif CVM_SYSMUTEX_ENTRY(heapLock, "heap lock"), CVM_SYSMUTEX_ENTRY(threadLock, "thread-list lock"), CVM_SYSMUTEX_ENTRY(classTableLock, "class table lock"), CVM_SYSMUTEX_ENTRY(loaderCacheLock, "loader cache lock"), /* NOTE: This is not a leaf mutex. It must remain below the global roots lock since a couple of the JVMTI routines allocate and deallocate global roots while holding the debugger lock. In addition, others of them perform indirect memory accesses while holding the debugger lock, so if we ever had a lock associated with those accesses it would need to have a higher rank (less importance) than this one. */#ifdef CVM_JVMTI CVM_SYSMUTEX_ENTRY(jvmtiLock, "jvmti lock"),#endif /* * All of these are "leaf" mutexes except during gc and during * during thread suspension. */ CVM_SYSMUTEX_ENTRY(globalRootsLock, "global roots lock"), CVM_SYSMUTEX_ENTRY(weakGlobalRootsLock, "weak global roots lock"), CVM_SYSMUTEX_ENTRY(typeidLock, "typeid lock"), CVM_SYSMUTEX_ENTRY(syncLock, "fast sync lock"), CVM_SYSMUTEX_ENTRY(internLock, "intern table lock"),#if defined(CVM_INSPECTOR) || defined(CVM_JVMPI) || defined(CVM_JVMTI) CVM_SYSMUTEX_ENTRY(gcLockerLock, "gc locker lock"),#endif#ifdef CVM_JVMPI CVM_SYSMUTEX_ENTRY(jvmpiSyncLock, "jvmpi sync lock"),#endif#ifdef CVM_JVMTI CVM_SYSMUTEX_ENTRY(jvmtiLockInfoLock, "jvmti lock info lock"),#endif#ifdef CVM_TIMESTAMPING CVM_SYSMUTEX_ENTRY(timestampListLock, "timestamp list lock"),#endif};#define CVM_NUM_GLOBAL_SYSMUTEXES \ (sizeof(globalSysMutexes) / sizeof(CVMGlobalSysMutexEntry))/* * The table of global mb's so we can easily init all of them. */typedef struct { CVMBool isStatic; CVMClassBlock* cb; const char* methodName; const char* methodSig; CVMMethodBlock** mbPtr;} CVMGlobalMethodBlockEntry;static const CVMGlobalMethodBlockEntry globalMethodBlocks[] = { /* AccessController.doPrivileged(PrivilegedAction) */ { CVM_TRUE, /* static */ CVMsystemClass(java_security_AccessController), "doPrivileged", "(Ljava/security/PrivilegedAction;)Ljava/lang/Object;", &CVMglobals.java_security_AccessController_doPrivilegedAction1, /* NOTE: java.security.AccessController has a static initializer, but a clinit check is not needed because this mb is not used to do any invocations. */ }, /* AccessController.doPrivileged(PrivilegedExceptionAction) */ { CVM_TRUE, /* static */ CVMsystemClass(java_security_AccessController), "doPrivileged", "(Ljava/security/PrivilegedExceptionAction;)Ljava/lang/Object;", &CVMglobals.java_security_AccessController_doPrivilegedExceptionAction1 /* NOTE: java.security.AccessController has a static initializer, but a clinit check is not needed because this mb is not used to do any invocations. */ }, /* AccessController.doPrivileged(PrivilegedAction, AccessControlContext) */ { CVM_TRUE, /* static */ CVMsystemClass(java_security_AccessController), "doPrivileged", "(Ljava/security/PrivilegedAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;", &CVMglobals.java_security_AccessController_doPrivilegedAction2 /* NOTE: java.security.AccessController has a static initializer, but a clinit check is not needed because this mb is not used to do any invocations. */ }, /* AccessController.doPrivileged(PrivilegedExceptionAction, AccessControlContext) */ { CVM_TRUE, /* static */ CVMsystemClass(java_security_AccessController), "doPrivileged", "(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;", &CVMglobals.java_security_AccessController_doPrivilegedExceptionAction2 /* NOTE: java.security.AccessController has a static initializer, but a clinit check is not needed because this mb is not used to do any invocations. */ }, /* java.lang.Shutdown.waitAllUserThreadsExitAndShutdown() */ { CVM_TRUE, /* static */ CVMsystemClass(java_lang_Shutdown), "waitAllUserThreadsExitAndShutdown", "()V", &CVMglobals.java_lang_Shutdown_waitAllUserThreadsExitAndShutdown /* NOTE: java.lang.Shutdown has a static initializer, but a clinit check is not needed because this mb is not used until after the class is initialized implicitly in JNI_CreateJavaVM().*/ }, /* sun.misc.ThreadRegistry.waitAllSystemThreadsExit() */ { CVM_TRUE, /* static */ CVMsystemClass(sun_misc_ThreadRegistry), "waitAllSystemThreadsExit", "()V", &CVMglobals.sun_misc_ThreadRegistry_waitAllSystemThreadsExit /* NOTE: sun.misc.ThreadRegistry has a static initializer. The clinit will be done explicitly in JNI_CreateJavaVM(). */ },#ifdef CVM_REFLECT /* java.lang.reflect.Constructor.newInstance() */ { CVM_FALSE, /* nonstatic */ CVMsystemClass(java_lang_reflect_Constructor), "newInstance", "([Ljava/lang/Object;)Ljava/lang/Object;", &CVMglobals.java_lang_reflect_Constructor_newInstance /* NOTE: No clinit check needed because this mb is not used to do any invocations. */ }, /* java.lang.reflect.Method.invoke() */ { CVM_FALSE, /* nonstatic */ CVMsystemClass(java_lang_reflect_Method), "invoke", "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;", &CVMglobals.java_lang_reflect_Method_invoke /* NOTE: No clinit check needed because this mb is not used to do any invocations. */ },#endif /* java.lang.ref.Finalizer.register() */ { CVM_TRUE, /* static */ CVMsystemClass(java_lang_ref_Finalizer), "register", "(Ljava/lang/Object;)V", &CVMglobals.java_lang_ref_Finalizer_register /* NOTE: java.lang.ref.Finalizer has a static initializer. The clinit will be done explicitly in JNI_CreateJavaVM(). */ },#ifdef CVM_LVM /* java.lang.ref.Finalizer.runAllFinalizersOfSystemClass() */ { CVM_TRUE, /* static */ CVMsystemClass(java_lang_ref_Finalizer), "runAllFinalizersOfSystemClass", "()V", &CVMglobals.java_lang_ref_Finalizer_runAllFinalizersOfSystemClass /* NOTE: java.lang.ref.Finalizer has a static initializer. The clinit will be done explicitly in JNI_CreateJavaVM(). */ },#endif#ifdef CVM_DEBUG_STACKTRACES /* java.lang.Throwable.fillInStackTrace() */ { CVM_FALSE, /* nonstatic */ CVMsystemClass(java_lang_Throwable), "fillInStackTrace", "()Ljava/lang/Throwable;", &CVMglobals.java_lang_Throwable_fillInStackTrace /* NOTE: No clinit check needed because this mb is not used to do any invocations. */ },#endif /* CVM_DEBUG_STACKTRACES */ /* java.lang.Class.runStaticInitializers() */ { CVM_FALSE, /* nonstatic */ CVMsystemClass(java_lang_Class), "runStaticInitializers", "()V", &CVMglobals.java_lang_Class_runStaticInitializers /* NOTE: java.lang.Class has a static initializer. The clinit will be done explicitly in JNI_CreateJavaVM(). */ }, /* java.lang.Class.newInstance() */ { CVM_FALSE, /* nonstatic */ CVMsystemClass(java_lang_Class), "newInstance", "()Ljava/lang/Object;", &CVMglobals.java_lang_Class_newInstance /* NOTE: java.lang.Class has a static initializer. The clinit will be done explicitly in JNI_CreateJavaVM(). */ },#ifdef CVM_CLASSLOADING /* java.lang.ClassLoader.NativeLibrary.getFromClass() */ { CVM_TRUE, /* static */ CVMsystemClass(java_lang_ClassLoader_NativeLibrary), "getFromClass", "()Ljava/lang/Class;", &CVMglobals.java_lang_ClassLoader_NativeLibrary_getFromClass /* NOTE: java.lang.ClassLoader.NativeLibrary has a static initializer. The clinit will be done explicitly in JNI_CreateJavaVM(). */ }, /* java.lang.ClassLoader.addClass() */ { CVM_FALSE, /* nonstatic */ CVMsystemClass(java_lang_ClassLoader), "addClass", "(Ljava/lang/Class;)V", &CVMglobals.java_lang_ClassLoader_addClass /* NOTE: java.lang.ClassLoader has a static initializer. The clinit will be done explicitly in JNI_CreateJavaVM(). */ }, /* java.lang.ClassLoader.loadClass() */ { CVM_FALSE, /* nonstatic */ CVMsystemClass(java_lang_ClassLoader), "loadClassInternal", "(Ljava/lang/String;)Ljava/lang/Class;", &CVMglobals.java_lang_ClassLoader_loadClass /* NOTE: java.lang.ClassLoader has a static initializer. The clinit will be done explicitly in JNI_CreateJavaVM(). */ }, /* java.lang.ClassLoader.findNative() */ { CVM_TRUE, /* static */ CVMsystemClass(java_lang_ClassLoader), "findNative", "(Ljava/lang/ClassLoader;Ljava/lang/String;)J", &CVMglobals.java_lang_ClassLoader_findNative /* NOTE: java.lang.ClassLoader has a static initializer. The clinit will be done explicitly in JNI_CreateJavaVM(). */ }, /* java.lang.ClassLoader.checkPackageAccess() */ { CVM_FALSE, /* nonstatic */ CVMsystemClass(java_lang_ClassLoader), "checkPackageAccess", "(Ljava/lang/Class;Ljava/security/ProtectionDomain;)V", &CVMglobals.java_lang_ClassLoader_checkPackageAccess /* NOTE: java.lang.ClassLoader has a static initializer. The clinit will be done explicitly in JNI_CreateJavaVM(). */ }, /* java.lang.ClassLoader.loadBootstrapClass() */ { CVM_TRUE, /* static */ CVMsystemClass(java_lang_ClassLoader), "loadBootstrapClass", "(Ljava/lang/String;)Ljava/lang/Class;", &CVMglobals.java_lang_ClassLoader_loadBootstrapClass /* NOTE: java.lang.ClassLoader has a static initializer. The clinit will be done explicitly in JNI_CreateJavaVM(). */ }, /* java.lang.Class.loadSuperClasses() */ { CVM_FALSE, /* nonstatic */ CVMsystemClass(java_lang_Class), "loadSuperClasses", "()V", &CVMglobals.java_lang_Class_loadSuperClasses },#endif /* java.lang.Thread.exit() */ { CVM_FALSE, /* nonstatic */ CVMsystemClass(java_lang_Thread), "exit", "(Ljava/lang/Throwable;)V", &CVMglobals.java_lang_Thread_exit /* NOTE: java.lang.Thread has a static initializer. The clinit will be done explicitly in JNI_CreateJavaVM(). */ }, /* java.lang.Thread.initMainThread() */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?