Brian Carlstrom | dd8af23 | 2012-05-13 23:56:07 -0700 | [diff] [blame] | 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 (2.5us on passion-eng at the time of writing), so we do |
| 26 | * all such lookups eagerly at startup. This means that code that never uses, say, |
| 27 | * java.util.zip.Deflater still has to pay for the lookup, but it means that on a device the cost |
| 28 | * is definitely paid during boot and amortized. A central cache also removes the temptation to |
| 29 | * dynamically call FindClass rather than add a small cache to each file that needs one. Another |
| 30 | * cost is that each class cached here requires a global reference, though in practice we save |
| 31 | * enough by not having a global reference for each file that uses a class such as java.lang.String |
| 32 | * which is used in several files. |
| 33 | * |
| 34 | * FindClass is still called in a couple of situations: when throwing exceptions, and in some of |
| 35 | * the serialization code. The former is clearly not a performance case, and we're currently |
| 36 | * assuming that neither is the latter. |
| 37 | * |
| 38 | * TODO: similar arguments hold for field and method IDs; we should cache them centrally too. |
| 39 | */ |
| 40 | struct JniConstants { |
| 41 | static void init(JNIEnv* env); |
| 42 | |
| 43 | static jclass bidiRunClass; |
| 44 | static jclass bigDecimalClass; |
| 45 | static jclass booleanClass; |
| 46 | static jclass byteArrayClass; |
| 47 | static jclass byteClass; |
Kenny Root | f4a3c1e | 2013-03-07 11:20:28 -0800 | [diff] [blame] | 48 | static jclass calendarClass; |
Brian Carlstrom | dd8af23 | 2012-05-13 23:56:07 -0700 | [diff] [blame] | 49 | static jclass characterClass; |
| 50 | static jclass charsetICUClass; |
| 51 | static jclass constructorClass; |
| 52 | static jclass deflaterClass; |
| 53 | static jclass doubleClass; |
| 54 | static jclass errnoExceptionClass; |
| 55 | static jclass fieldClass; |
| 56 | static jclass fieldPositionIteratorClass; |
| 57 | static jclass fileDescriptorClass; |
| 58 | static jclass floatClass; |
| 59 | static jclass gaiExceptionClass; |
| 60 | static jclass inet6AddressClass; |
| 61 | static jclass inetAddressClass; |
| 62 | static jclass inetSocketAddressClass; |
Elliott Hughes | 95b0038 | 2013-03-21 12:08:11 -0700 | [diff] [blame] | 63 | static jclass inetUnixAddressClass; |
Brian Carlstrom | dd8af23 | 2012-05-13 23:56:07 -0700 | [diff] [blame] | 64 | static jclass inflaterClass; |
Elliott Hughes | 48f1451 | 2013-03-06 09:43:43 -0800 | [diff] [blame] | 65 | static jclass inputStreamClass; |
Brian Carlstrom | dd8af23 | 2012-05-13 23:56:07 -0700 | [diff] [blame] | 66 | static jclass integerClass; |
| 67 | static jclass localeDataClass; |
| 68 | static jclass longClass; |
| 69 | static jclass methodClass; |
| 70 | static jclass mutableIntClass; |
| 71 | static jclass mutableLongClass; |
Kenny Root | f4a3c1e | 2013-03-07 11:20:28 -0800 | [diff] [blame] | 72 | static jclass objectClass; |
| 73 | static jclass objectArrayClass; |
Elliott Hughes | 48f1451 | 2013-03-06 09:43:43 -0800 | [diff] [blame] | 74 | static jclass outputStreamClass; |
Brian Carlstrom | dd8af23 | 2012-05-13 23:56:07 -0700 | [diff] [blame] | 75 | static jclass parsePositionClass; |
| 76 | static jclass patternSyntaxExceptionClass; |
| 77 | static jclass realToStringClass; |
| 78 | static jclass shortClass; |
| 79 | static jclass socketClass; |
| 80 | static jclass socketImplClass; |
Brian Carlstrom | dd8af23 | 2012-05-13 23:56:07 -0700 | [diff] [blame] | 81 | static jclass stringClass; |
| 82 | static jclass structAddrinfoClass; |
| 83 | static jclass structFlockClass; |
| 84 | static jclass structGroupReqClass; |
| 85 | static jclass structLingerClass; |
| 86 | static jclass structPasswdClass; |
| 87 | static jclass structPollfdClass; |
| 88 | static jclass structStatClass; |
Elliott Hughes | 47a1f29 | 2013-07-09 13:59:11 -0700 | [diff] [blame^] | 89 | static jclass structStatVfsClass; |
Brian Carlstrom | dd8af23 | 2012-05-13 23:56:07 -0700 | [diff] [blame] | 90 | static jclass structTimevalClass; |
Elliott Hughes | 95b0038 | 2013-03-21 12:08:11 -0700 | [diff] [blame] | 91 | static jclass structUcredClass; |
Brian Carlstrom | dd8af23 | 2012-05-13 23:56:07 -0700 | [diff] [blame] | 92 | static jclass structUtsnameClass; |
| 93 | }; |
| 94 | |
| 95 | #define NATIVE_METHOD(className, functionName, signature) \ |
| 96 | { #functionName, signature, reinterpret_cast<void*>(className ## _ ## functionName) } |
| 97 | |
| 98 | #endif // JNI_CONSTANTS_H_included |