1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef JNI_CONSTANTS_H_included 18 #define JNI_CONSTANTS_H_included 19 20 #include "JNIHelp.h" 21 22 /** 23 * A cache to avoid calling FindClass at runtime. 24 * 25 * Class lookup is relatively expensive, so we do these lookups at startup. This means that code 26 * that never uses, say, java.util.zip.Deflater still has to pay for the lookup, but it means that 27 * on device the cost is paid during boot and amortized. A central cache also removes the temptation 28 * to dynamically call FindClass rather than add a small cache to each file that needs one. Another 29 * cost is that each class cached here requires a global reference, though in practice we save 30 * enough by not having a global reference for each file that uses a class such as java.lang.String 31 * which is used in several files. 32 * 33 * FindClass is still called in a couple of situations: when throwing exceptions, and in some of 34 * the serialization code. The former is clearly not a performance case, and we're currently 35 * assuming that neither is the latter. 36 * 37 * TODO: similar arguments hold for field and method IDs; we should cache them centrally too. 38 */ 39 struct JniConstants { 40 static void init(JNIEnv* env); 41 42 static jclass bidiRunClass; 43 static jclass bigDecimalClass; 44 static jclass booleanClass; 45 static jclass byteArrayClass; 46 static jclass byteClass; 47 static jclass calendarClass; 48 static jclass characterClass; 49 static jclass charsetICUClass; 50 static jclass constructorClass; 51 static jclass deflaterClass; 52 static jclass doubleClass; 53 static jclass errnoExceptionClass; 54 static jclass fieldClass; 55 static jclass fieldPositionIteratorClass; 56 static jclass fileDescriptorClass; 57 static jclass floatClass; 58 static jclass gaiExceptionClass; 59 static jclass inet6AddressClass; 60 static jclass inetAddressClass; 61 static jclass inetSocketAddressClass; 62 static jclass inetUnixAddressClass; 63 static jclass inflaterClass; 64 static jclass inputStreamClass; 65 static jclass integerClass; 66 static jclass localeDataClass; 67 static jclass longClass; 68 static jclass methodClass; 69 static jclass mutableIntClass; 70 static jclass mutableLongClass; 71 static jclass netlinkSocketAddressClass; 72 static jclass objectClass; 73 static jclass objectArrayClass; 74 static jclass outputStreamClass; 75 static jclass packetSocketAddressClass; 76 static jclass parsePositionClass; 77 static jclass patternSyntaxExceptionClass; 78 static jclass realToStringClass; 79 static jclass referenceClass; 80 static jclass shortClass; 81 static jclass socketClass; 82 static jclass socketImplClass; 83 static jclass stringClass; 84 static jclass structAddrinfoClass; 85 static jclass structFlockClass; 86 static jclass structGroupReqClass; 87 static jclass structGroupSourceReqClass; 88 static jclass structLingerClass; 89 static jclass structPasswdClass; 90 static jclass structPollfdClass; 91 static jclass structStatClass; 92 static jclass structStatVfsClass; 93 static jclass structTimevalClass; 94 static jclass structUcredClass; 95 static jclass structUtsnameClass; 96 static jclass zipEntryClass; 97 }; 98 99 #define NATIVE_METHOD(className, functionName, signature) \ 100 { #functionName, signature, reinterpret_cast<void*>(className ## _ ## functionName) } 101 102 #endif // JNI_CONSTANTS_H_included 103