utils.h
来自「This is a resource based on j2me embedde」· C头文件 代码 · 共 508 行 · 第 1/2 页
H
508 行
/* * @(#)utils.h 1.96 06/10/10 * * 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. * *//* * Header file for various utility functions and macros. */#ifndef CVM_UTILS_H#define CVM_UTILS_H#include "javavm/include/defs.h"#include "javavm/include/clib.h"#include "javavm/include/typeid.h"#include "javavm/include/basictypes.h"#include "javavm/include/porting/globals.h"#include "javavm/include/porting/ansi/stdarg.h"#include "javavm/export/jni.h"#include "generated/cni/sun_misc_CVM.h"/* * Console I/O. Same as printf, but supports special formats like * %C, %P, and %F. See CVMformatStringVaList for details. */void CVMconsolePrintf(const char* format, ...);/* * Dump an exception using CVMconsolePrintf. Useful for failures during * vm startup and for debugging in gdb. */voidCVMdumpException(CVMExecEnv* ee);/* * Functions for accessing the debugging flags. All of the following functions * return the previous state of the flag. * * You can pass in more than one flag at a time to any of the functions. */#define CVM_DEBUGFLAG(flag) (sun_misc_CVM_DEBUGFLAG_##flag)#ifdef CVM_TRACE_ENABLEDextern CVMInt32CVMcheckDebugFlags(CVMInt32 flags);#define CVMcheckDebugFlags(flags) (CVMglobals.debugFlags & (flags))extern CVMInt32CVMsetDebugFlags(CVMInt32 flags);extern CVMInt32CVMclearDebugFlags(CVMInt32 flags);extern CVMInt32CVMrestoreDebugFlags(CVMInt32 flags, CVMInt32 oldvalue);#endif /* CVM_TRACE_ENABLED *//* * Debug I/O */#ifdef CVM_DEBUG#define CVMdebugPrintf(x) CVMconsolePrintf x#define CVMdebugExec(x) x#else#define CVMdebugPrintf(x)#define CVMdebugExec(x)#endif /* CVM_DEBUG *//* * Trace I/O */#ifdef CVM_TRACE#define CVMtrace(flags, x) \ (CVMcheckDebugFlags(flags) != 0 ? CVMconsolePrintf x : (void)0)#define CVMtraceExec(flags, x) \ if (CVMcheckDebugFlags(flags) != 0) x#define CVMeeTrace(flags, x) \ (((ee)->debugFlags & (flags)) != 0 ? CVMconsolePrintf x : (void)0)#else#define CVMtrace(flags, x)#define CVMtraceExec(flags, x)#define CVMeeTrace(flags, x)#endif /* CVM_TRACE */#define CVMtraceOpcode(x) CVMeeTrace(CVM_DEBUGFLAG(TRACE_OPCODE), x)#define CVMtraceStatus(x) CVMtrace(CVM_DEBUGFLAG(TRACE_STATUS), x)#define CVMtraceFastLock(x) CVMeeTrace(CVM_DEBUGFLAG(TRACE_FASTLOCK), x)#define CVMtraceDetLock(x) CVMeeTrace(CVM_DEBUGFLAG(TRACE_DETLOCK), x)#define CVMtraceSysMutex(x) CVMeeTrace(CVM_DEBUGFLAG(TRACE_MUTEX), x)#define CVMtraceCS(x) CVMtrace(CVM_DEBUGFLAG(TRACE_CS), x)#define CVMtraceGcStartStop(x) CVMtrace(CVM_DEBUGFLAG(TRACE_GCSTARTSTOP) | \ CVM_DEBUGFLAG(TRACE_GCSCAN), x)#define CVMtraceGcScan(x) CVMtrace(CVM_DEBUGFLAG(TRACE_GCSCAN), x)#define CVMtraceGcAlloc(x) CVMtrace(CVM_DEBUGFLAG(TRACE_GCALLOC), x)#define CVMtraceGcCollect(x) CVMtrace(CVM_DEBUGFLAG(TRACE_GCCOLLECT), x)#define CVMtraceGcSafety(x) CVMtrace(CVM_DEBUGFLAG(TRACE_GCSAFETY), x)#define CVMtraceClinit(x) CVMtrace(CVM_DEBUGFLAG(TRACE_CLINIT), x)#define CVMtraceExceptions(x) CVMtrace(CVM_DEBUGFLAG(TRACE_EXCEPTIONS), x)#define CVMtraceMisc(x) CVMtrace(CVM_DEBUGFLAG(TRACE_MISC), x)#define CVMtraceBarriers(x) CVMtrace(CVM_DEBUGFLAG(TRACE_BARRIERS), x)#define CVMtraceStackmaps(x) CVMtrace(CVM_DEBUGFLAG(TRACE_STACKMAPS), x)#define CVMtraceClassLoading(x) CVMtrace(CVM_DEBUGFLAG(TRACE_CLASSLOADING), x)#define CVMtraceClassLookup(x) CVMtrace(CVM_DEBUGFLAG(TRACE_CLASSLOOKUP), x)#define CVMtraceTypeID(x) CVMtrace(CVM_DEBUGFLAG(TRACE_TYPEID), x)#define CVMtraceVerifier(x) CVMtrace(CVM_DEBUGFLAG(TRACE_VERIFIER), x)#define CVMtraceWeakrefs(x) CVMtrace(CVM_DEBUGFLAG(TRACE_WEAKREFS), x)#define CVMtraceClassUnloading(x) CVMtrace(CVM_DEBUGFLAG(TRACE_CLASSUNLOAD), x)#define CVMtraceClassLink(x) CVMtrace(CVM_DEBUGFLAG(TRACE_CLASSLINK), x)#define CVMtraceJVMTI(x) CVMtrace(CVM_DEBUGFLAG(TRACE_JVMTI), x)#ifdef CVM_LVM /* %begin lvm */#define CVMtraceLVM(x) CVMtrace(CVM_DEBUGFLAG(TRACE_LVM), x)#endif /* %end lvm *//* * Long utility routines: */#if defined(CVM_DEBUG) || defined(CVM_TRACE_ENABLED)extern void CVMlong2String(CVMInt64, char*, char*);#endif/* * Java class utility routines: */#ifdef CVM_DEBUGvoidCVMdumpThread(JNIEnv* env);/* Prints the thread name with NO additional characters to stdout. Prints "<unnamed thread>" if thread has NULL name. */voidCVMprintThreadName(JNIEnv* env, CVMObjectICell* threadICell);#endifextern char*CVMclassname2String(CVMClassTypeID classTypeID, char *dst, int size);/* * UTF8/Unicode *//* * Number of Unicode characters represented by the null-terminated, * UTF8-encoded C string */extern CVMSize CVMutfLength(const char *);/* * counted copy from UTF8 string to unicode array. * count is number of Unicode characters to copy. * returned value is number of UTF8 characters consumed. */extern intCVMutfCountedCopyIntoCharArray( const char * utf8Bytes, CVMJavaChar* unicodeChars, CVMSize unicodeLength );extern void CVMutfCopyIntoCharArray(const char* utf8Bytes, CVMJavaChar* unicodeChars);extern char* CVMutfCopyFromCharArray(const CVMJavaChar* unicodeChars, char* utf8Bytes, CVMInt32 count);extern CVMJavaCharCVMutfNextUnicodeChar(const char** utf8String_p);#define CVMunicodeChar2UtfLength(ch) \ (((ch != 0) && (ch <= 0x7f)) ? 1 /* 1 byte */ \ : (ch <= 0x7FF) ? 2 /* 2 byte character */ \ : 3) /* 3 byte character *//* * Format a string. Implements VM-specific formats plus a subset of * snprintf formats. See utils.c for details. */size_tCVMformatString(char *buf, size_t bufSize, const char *format, ...);size_tCVMformatStringVaList(char *buf, size_t bufSize, const char *format, va_list ap);/* * Java String utils */extern voidCVMnewStringUTF(CVMExecEnv* ee, CVMStringICell* resultICell, const char* utf8Bytes);extern voidCVMnewString(CVMExecEnv* ee, CVMStringICell* resultICell, const CVMJavaChar* unicodeChars, CVMUint32 len);/* * Alignment *//* * CVMalignDoubleWordUp(val), CVMalignWordUp(val), * CVMalignDoubleWordDown(val), CVMalignWordDown(val) * val is used for address arithmetic * therefore the cast has to be CVMAddr which is 4 byte on * 32 bit platforms and 8 byte on 64 bit platforms */#define CVMalignDoubleWordUp(val) (((CVMAddr)(val) + 7) & ~7)#define CVMalignWordUp(val) (((CVMAddr)(val) + 3) & ~3)#define CVMalignDoubleWordDown(val) ((CVMAddr)(val) & ~7)#define CVMalignWordDown(val) ((CVMAddr)(val) & ~3)/* * These macros are intended to make sure the * correct pointer alignment is used: 4-byte on * 32 bit platforms and 8-byte on 64 bit platforms. */#ifdef CVM_64#define CVMalignAddrUp(val) (((CVMAddr)(val) + 7) & ~7)#define CVMalignAddrDown(val) ((CVMAddr)(val) & ~7)#else#define CVMalignAddrUp(val) (((CVMAddr)(val) + 3) & ~3)#define CVMalignAddrDown(val) ((CVMAddr)(val) & ~3)#endif/* * Returns true if the two classes are in the same package. */CVMBool CVMisSameClassPackage(CVMExecEnv* ee, CVMClassBlock* class1, CVMClassBlock* class2);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?