1f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 2f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project 3f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * 4f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 5f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * you may not use this file except in compliance with the License. 6f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * You may obtain a copy of the License at 7f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * 8f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 9f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * 10f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 11f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 12f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * See the License for the specific language governing permissions and 14f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * limitations under the License. 15f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 1699409883d9c4c0ffb49b070ce307bb33a9dfe9f1The Android Open Source Project 17f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 18f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Miscellaneous utility functions. 19f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 20f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#ifndef _DALVIK_MISC 21f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#define _DALVIK_MISC 22f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 23f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#include "Inlines.h" 24f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 25f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#include <stdio.h> 26f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#include <sys/types.h> 27f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#include <sys/time.h> 28f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 29f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 30f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Used to shut up the compiler when a parameter isn't used. 31f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 32f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#define UNUSED_PARAMETER(p) (void)(p) 33f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 34f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 35f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Floating point conversion functions. These are necessary to avoid 36f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * strict-aliasing problems ("dereferencing type-punned pointer will break 37f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * strict-aliasing rules"). According to the gcc info page, this usage 38f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * is allowed, even with "-fstrict-aliasing". 39f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * 40f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * The code generated by gcc-4.1.1 appears to be much better than a 41f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * type cast dereference ("int foo = *(int*)&myfloat") when the conversion 42f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * function is inlined. It also allows us to take advantage of the 43f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * optimizations that strict aliasing rules allow. 44f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 45f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source ProjectINLINE float dvmU4ToFloat(u4 val) { 46f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project union { u4 in; float out; } conv; 47f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project conv.in = val; 48f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project return conv.out; 49f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project} 50f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source ProjectINLINE u4 dvmFloatToU4(float val) { 51f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project union { float in; u4 out; } conv; 52f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project conv.in = val; 53f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project return conv.out; 54f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project} 55f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 56f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 57f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Print a hex dump to the log file. 58f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * 59f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * "local" mode prints a hex dump starting from offset 0 (roughly equivalent 60f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * to "xxd -g1"). 61f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * 62f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * "mem" mode shows the actual memory address, and will offset the start 63f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * so that the low nibble of the address is always zero. 64f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * 65f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * If "tag" is NULL the default tag ("dalvikvm") will be used. 66f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 67f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projecttypedef enum { kHexDumpLocal, kHexDumpMem } HexDumpMode; 68f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectvoid dvmPrintHexDumpEx(int priority, const char* tag, const void* vaddr, 69f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project size_t length, HexDumpMode mode); 70f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 71f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 72f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Print a hex dump, at INFO level. 73f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 74f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source ProjectINLINE void dvmPrintHexDump(const void* vaddr, size_t length) { 75f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project dvmPrintHexDumpEx(ANDROID_LOG_INFO, LOG_TAG, 76f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project vaddr, length, kHexDumpLocal); 77f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project} 78f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 79f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 80f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Print a hex dump at VERBOSE level. This does nothing in non-debug builds. 81f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 82f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source ProjectINLINE void dvmPrintHexDumpDbg(const void* vaddr, size_t length,const char* tag) 83f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project{ 84f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#if !LOG_NDEBUG 85f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project dvmPrintHexDumpEx(ANDROID_LOG_VERBOSE, (tag != NULL) ? tag : LOG_TAG, 86f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project vaddr, length, kHexDumpLocal); 87f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#endif 88f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project} 89f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 90f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 91f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * We pass one of these around when we want code to be able to write debug 92f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * info to either the log or to a file (or stdout/stderr). 93f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 94f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projecttypedef struct DebugOutputTarget { 95f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project /* where to? */ 96f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project enum { 97f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project kDebugTargetUnknown = 0, 98f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project kDebugTargetLog, 99f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project kDebugTargetFile, 100f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project } which; 101f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 102f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project /* additional bits */ 103f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project union { 104f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project struct { 105f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project int priority; 106f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project const char* tag; 107f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project } log; 108f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project struct { 109f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project FILE* fp; 110f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project } file; 111f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project } data; 112f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project} DebugOutputTarget; 113f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 114f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 115f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Fill in a DebugOutputTarget struct. 116f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 117f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectvoid dvmCreateLogOutputTarget(DebugOutputTarget* target, int priority, 118f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project const char* tag); 119f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectvoid dvmCreateFileOutputTarget(DebugOutputTarget* target, FILE* fp); 120f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 121f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 122f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Print a debug message. 123f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 124f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectvoid dvmPrintDebugMessage(const DebugOutputTarget* target, const char* format, 12599409883d9c4c0ffb49b070ce307bb33a9dfe9f1The Android Open Source Project ...) 12699409883d9c4c0ffb49b070ce307bb33a9dfe9f1The Android Open Source Project#if defined(__GNUC__) 12799409883d9c4c0ffb49b070ce307bb33a9dfe9f1The Android Open Source Project __attribute__ ((format(printf, 2, 3))) 12899409883d9c4c0ffb49b070ce307bb33a9dfe9f1The Android Open Source Project#endif 12999409883d9c4c0ffb49b070ce307bb33a9dfe9f1The Android Open Source Project ; 130f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 131f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 132f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 133f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Expanding bitmap, used for tracking resources. Bits are numbered starting 134f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * from zero. 135f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * 136f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * All operations on a BitVector are unsynchronized. 137f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 138f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projecttypedef struct BitVector { 139f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project bool expandable; /* expand bitmap if we run out? */ 140f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project int storageSize; /* current size, in 32-bit words */ 141f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project u4* storage; 142f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project} BitVector; 143f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 144f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* allocate a bit vector with enough space to hold "startBits" bits */ 145f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source ProjectBitVector* dvmAllocBitVector(int startBits, bool expandable); 146f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectvoid dvmFreeBitVector(BitVector* pBits); 147f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 148f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 149f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * dvmAllocBit always allocates the first possible bit. If we run out of 150f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * space in the bitmap, and it's not marked expandable, dvmAllocBit 151f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * returns -1. 152f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * 153f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * dvmSetBit sets the specified bit, expanding the vector if necessary 154f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * (and possible). 155f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * 156f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * dvmIsBitSet returns "true" if the bit is set. 157f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 158f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectint dvmAllocBit(BitVector* pBits); 159f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectbool dvmSetBit(BitVector* pBits, int num); 160f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectvoid dvmClearBit(BitVector* pBits, int num); 161e9695e5d281ad8bfbe3091e825befbedfc1b2007Ben Chengvoid dvmClearAllBits(BitVector* pBits); 162f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectbool dvmIsBitSet(const BitVector* pBits, int num); 163f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 164f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* count the number of bits that have been set */ 165f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectint dvmCountSetBits(const BitVector* pBits); 166f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 1674238ec2ad1ace5103b2206a483f5f03d2e96c476Ben Cheng/* copy one vector to the other compatible one */ 1684238ec2ad1ace5103b2206a483f5f03d2e96c476Ben Chengbool dvmCopyBitVector(BitVector *dest, const BitVector *src); 1694238ec2ad1ace5103b2206a483f5f03d2e96c476Ben Cheng 1704238ec2ad1ace5103b2206a483f5f03d2e96c476Ben Cheng/* 1714238ec2ad1ace5103b2206a483f5f03d2e96c476Ben Cheng * Intersect two bit vectores and merge the result on top of the pre-existing 1724238ec2ad1ace5103b2206a483f5f03d2e96c476Ben Cheng * value in the dest vector. 1734238ec2ad1ace5103b2206a483f5f03d2e96c476Ben Cheng */ 1744238ec2ad1ace5103b2206a483f5f03d2e96c476Ben Chengbool dvmIntersectBitVectors(BitVector *dest, const BitVector *src1, 1754238ec2ad1ace5103b2206a483f5f03d2e96c476Ben Cheng const BitVector *src2); 1764238ec2ad1ace5103b2206a483f5f03d2e96c476Ben Cheng 177f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#define kBitVectorGrowth 4 /* increase by 4 u4s when limit hit */ 178f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 179f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 180f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 181f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Return a newly-allocated string in which all occurrences of '.' have 182f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * been changed to '/'. If we find a '/' in the original string, NULL 183f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * is returned to avoid ambiguity. 184f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 185f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectchar* dvmDotToSlash(const char* str); 186f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 187f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 188f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Return a newly-allocated string for the "dot version" of the class 189f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * name for the given type descriptor. That is, The initial "L" and 190f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * final ";" (if any) have been removed and all occurrences of '/' 191f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * have been changed to '.'. 192f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 193f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectchar* dvmDescriptorToDot(const char* str); 194f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 195f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 196f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Return a newly-allocated string for the type descriptor 197f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * corresponding to the "dot version" of the given class name. That 198f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * is, non-array names are surrounde by "L" and ";", and all 199f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * occurrences of '.' have been changed to '/'. 200f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 201f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectchar* dvmDotToDescriptor(const char* str); 202f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 203f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 204f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Return a newly-allocated string for the internal-form class name for 205f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * the given type descriptor. That is, the initial "L" and final ";" (if 206f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * any) have been removed. 207f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 208f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectchar* dvmDescriptorToName(const char* str); 209f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 210f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 211f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Return a newly-allocated string for the type descriptor for the given 212f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * internal-form class name. That is, a non-array class name will get 213f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * surrounded by "L" and ";", while array names are left as-is. 214f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 215f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectchar* dvmNameToDescriptor(const char* str); 216f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 217f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 218f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Get the current time, in nanoseconds. This is "relative" time, meaning 219f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * it could be wall-clock time or a monotonic counter, and is only suitable 220f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * for computing time deltas. 221f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 222f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectu8 dvmGetRelativeTimeNsec(void); 223f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 224f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 225f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Get the current time, in microseconds. This is "relative" time, meaning 226f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * it could be wall-clock time or a monotonic counter, and is only suitable 227f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * for computing time deltas. 228f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 229f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source ProjectINLINE u8 dvmGetRelativeTimeUsec(void) { 230f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project return dvmGetRelativeTimeNsec() / 1000; 231f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project} 232f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 233f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 23403f3b1394cc8421d125fd00455858944f0e9808dCarl Shapiro * Get the current time, in milliseconds. This is "relative" time, 23503f3b1394cc8421d125fd00455858944f0e9808dCarl Shapiro * meaning it could be wall-clock time or a monotonic counter, and is 23603f3b1394cc8421d125fd00455858944f0e9808dCarl Shapiro * only suitable for computing time deltas. The value returned from 23703f3b1394cc8421d125fd00455858944f0e9808dCarl Shapiro * this function is a u4 and should only be used for debugging 23803f3b1394cc8421d125fd00455858944f0e9808dCarl Shapiro * messages. TODO: make this value relative to the start-up time of 23903f3b1394cc8421d125fd00455858944f0e9808dCarl Shapiro * the VM. 24003f3b1394cc8421d125fd00455858944f0e9808dCarl Shapiro */ 24103f3b1394cc8421d125fd00455858944f0e9808dCarl ShapiroINLINE u4 dvmGetRelativeTimeMsec(void) { 24203f3b1394cc8421d125fd00455858944f0e9808dCarl Shapiro return (u4)(dvmGetRelativeTimeUsec() / 1000); 24303f3b1394cc8421d125fd00455858944f0e9808dCarl Shapiro} 24403f3b1394cc8421d125fd00455858944f0e9808dCarl Shapiro 24503f3b1394cc8421d125fd00455858944f0e9808dCarl Shapiro/* 246f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Get the current per-thread CPU time. This clock increases monotonically 247f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * when the thread is running, but not when it's sleeping or blocked on a 248f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * synchronization object. 249f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * 250f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * The absolute value of the clock may not be useful, so this should only 251f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * be used for time deltas. 252f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * 253f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * If the thread CPU clock is not available, this always returns (u8)-1. 254f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 255f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectu8 dvmGetThreadCpuTimeNsec(void); 256f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 257f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 258f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Per-thread CPU time, in micros. 259f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 260f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source ProjectINLINE u8 dvmGetThreadCpuTimeUsec(void) { 261f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project return dvmGetThreadCpuTimeNsec() / 1000; 262f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project} 263f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 264f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 265f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Like dvmGetThreadCpuTimeNsec, but for a different thread. 266f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 267f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectu8 dvmGetOtherThreadCpuTimeNsec(pthread_t thread); 268f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source ProjectINLINE u8 dvmGetOtherThreadCpuTimeUsec(pthread_t thread) { 269f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project return dvmGetOtherThreadCpuTimeNsec(thread) / 1000; 270f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project} 271f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 272f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 273f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Sleep for increasingly longer periods, until "maxTotalSleep" microseconds 274f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * have elapsed. Pass in the start time, which must be a value returned by 275f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * dvmGetRelativeTimeUsec(). 276f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * 277f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Returns "false" if we were unable to sleep because our time is up. 278f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 279f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectbool dvmIterativeSleep(int iteration, int maxTotalSleep, u8 relStartTime); 280f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 281f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 282f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Set the "close on exec" flag on a file descriptor. 283f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 284f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectbool dvmSetCloseOnExec(int fd); 285f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 28699409883d9c4c0ffb49b070ce307bb33a9dfe9f1The Android Open Source Project/* 28799409883d9c4c0ffb49b070ce307bb33a9dfe9f1The Android Open Source Project * Unconditionally abort the entire VM. Try not to use this. 288bb710e3294c57587f327c5e365353af81aa2cb5fAndy McFadden * 289bb710e3294c57587f327c5e365353af81aa2cb5fAndy McFadden * NOTE: if this is marked ((noreturn)), gcc will merge multiple dvmAbort() 290bb710e3294c57587f327c5e365353af81aa2cb5fAndy McFadden * calls in a single function together. This is good, in that it reduces 291bb710e3294c57587f327c5e365353af81aa2cb5fAndy McFadden * code size slightly, but also bad, because the native stack trace we 292bb710e3294c57587f327c5e365353af81aa2cb5fAndy McFadden * get from the abort may point at the wrong call site. Best to leave 293bb710e3294c57587f327c5e365353af81aa2cb5fAndy McFadden * it undecorated. 29499409883d9c4c0ffb49b070ce307bb33a9dfe9f1The Android Open Source Project */ 295bb710e3294c57587f327c5e365353af81aa2cb5fAndy McFaddenvoid dvmAbort(void); 29699409883d9c4c0ffb49b070ce307bb33a9dfe9f1The Android Open Source Project 297f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#if (!HAVE_STRLCPY) 298f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* Implementation of strlcpy() for platforms that don't already have it. */ 299f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectsize_t strlcpy(char *dst, const char *src, size_t size); 300f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#endif 301f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 3026e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes/* 3036e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * Allocates a memory region using ashmem and mmap, initialized to 3046e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * zero. Actual allocation rounded up to page multiple. Returns 3056e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * NULL on failure. 3066e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes */ 3076e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayesvoid *dvmAllocRegion(size_t size, int prot, const char *name); 3086e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes 30932bc0787307ba57e92fa74c52da550e2ca22af7fDan Bornstein/* 31032bc0787307ba57e92fa74c52da550e2ca22af7fDan Bornstein * Returns the pointer to the "absolute path" part of the given path 31132bc0787307ba57e92fa74c52da550e2ca22af7fDan Bornstein * string, treating first (if any) instance of "/./" as a sentinel 31232bc0787307ba57e92fa74c52da550e2ca22af7fDan Bornstein * indicating the start of the absolute path. If the path isn't absolute 31332bc0787307ba57e92fa74c52da550e2ca22af7fDan Bornstein * in the usual way (i.e., starts with "/") and doesn't have the sentinel, 31432bc0787307ba57e92fa74c52da550e2ca22af7fDan Bornstein * then this returns NULL. 31532bc0787307ba57e92fa74c52da550e2ca22af7fDan Bornstein * 31632bc0787307ba57e92fa74c52da550e2ca22af7fDan Bornstein * For example: 31732bc0787307ba57e92fa74c52da550e2ca22af7fDan Bornstein * "/foo/bar/baz" returns "/foo/bar/baz" 31832bc0787307ba57e92fa74c52da550e2ca22af7fDan Bornstein * "foo/./bar/baz" returns "/bar/baz" 31932bc0787307ba57e92fa74c52da550e2ca22af7fDan Bornstein * "foo/bar/baz" returns NULL 32032bc0787307ba57e92fa74c52da550e2ca22af7fDan Bornstein * 32132bc0787307ba57e92fa74c52da550e2ca22af7fDan Bornstein * The sentinel is used specifically to aid in cross-optimization, where 32232bc0787307ba57e92fa74c52da550e2ca22af7fDan Bornstein * a host is processing dex files in a build tree, and where we don't want 32332bc0787307ba57e92fa74c52da550e2ca22af7fDan Bornstein * the build tree's directory structure to be baked into the output (such 32432bc0787307ba57e92fa74c52da550e2ca22af7fDan Bornstein * as, for example, in the dependency paths of optimized dex files). 32532bc0787307ba57e92fa74c52da550e2ca22af7fDan Bornstein */ 32632bc0787307ba57e92fa74c52da550e2ca22af7fDan Bornsteinconst char* dvmPathToAbsolutePortion(const char* path); 32732bc0787307ba57e92fa74c52da550e2ca22af7fDan Bornstein 328f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#endif /*_DALVIK_MISC*/ 329