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 | * |
Lorenzo Colitti | 63daad5 | 2015-03-12 01:22:36 +0900 | [diff] [blame] | 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 |
Brian Carlstrom | dd8af23 | 2012-05-13 23:56:07 -0700 | [diff] [blame] | 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 | |
Brian Carlstrom | dd8af23 | 2012-05-13 23:56:07 -0700 | [diff] [blame] | 42 | static jclass bigDecimalClass; |
| 43 | static jclass booleanClass; |
| 44 | static jclass byteArrayClass; |
| 45 | static jclass byteClass; |
Kenny Root | f4a3c1e | 2013-03-07 11:20:28 -0800 | [diff] [blame] | 46 | static jclass calendarClass; |
Brian Carlstrom | dd8af23 | 2012-05-13 23:56:07 -0700 | [diff] [blame] | 47 | static jclass characterClass; |
| 48 | static jclass charsetICUClass; |
| 49 | static jclass constructorClass; |
| 50 | static jclass deflaterClass; |
| 51 | static jclass doubleClass; |
| 52 | static jclass errnoExceptionClass; |
| 53 | static jclass fieldClass; |
Brian Carlstrom | dd8af23 | 2012-05-13 23:56:07 -0700 | [diff] [blame] | 54 | static jclass fileDescriptorClass; |
| 55 | static jclass floatClass; |
| 56 | static jclass gaiExceptionClass; |
| 57 | static jclass inet6AddressClass; |
| 58 | static jclass inetAddressClass; |
Piotr Jastrzebski | 6ea79a1 | 2015-05-06 14:00:36 +0100 | [diff] [blame] | 59 | static jclass inetAddressHolderClass; |
Brian Carlstrom | dd8af23 | 2012-05-13 23:56:07 -0700 | [diff] [blame] | 60 | static jclass inetSocketAddressClass; |
Piotr Jastrzebski | 75fc6d2 | 2015-06-02 10:58:22 +0100 | [diff] [blame] | 61 | static jclass inetSocketAddressHolderClass; |
Brian Carlstrom | dd8af23 | 2012-05-13 23:56:07 -0700 | [diff] [blame] | 62 | static jclass inflaterClass; |
Elliott Hughes | 48f1451 | 2013-03-06 09:43:43 -0800 | [diff] [blame] | 63 | static jclass inputStreamClass; |
Brian Carlstrom | dd8af23 | 2012-05-13 23:56:07 -0700 | [diff] [blame] | 64 | static jclass integerClass; |
| 65 | static jclass localeDataClass; |
| 66 | static jclass longClass; |
| 67 | static jclass methodClass; |
| 68 | static jclass mutableIntClass; |
| 69 | static jclass mutableLongClass; |
Erik Kline | 25b67b1 | 2015-02-25 18:33:29 +0900 | [diff] [blame] | 70 | static jclass netlinkSocketAddressClass; |
Kenny Root | f4a3c1e | 2013-03-07 11:20:28 -0800 | [diff] [blame] | 71 | static jclass objectClass; |
| 72 | static jclass objectArrayClass; |
Elliott Hughes | 48f1451 | 2013-03-06 09:43:43 -0800 | [diff] [blame] | 73 | static jclass outputStreamClass; |
Lorenzo Colitti | 63daad5 | 2015-03-12 01:22:36 +0900 | [diff] [blame] | 74 | static jclass packetSocketAddressClass; |
Brian Carlstrom | dd8af23 | 2012-05-13 23:56:07 -0700 | [diff] [blame] | 75 | static jclass parsePositionClass; |
| 76 | static jclass patternSyntaxExceptionClass; |
Jeff Brown | dc176c5 | 2013-04-02 18:09:29 -0700 | [diff] [blame] | 77 | static jclass referenceClass; |
Brian Carlstrom | dd8af23 | 2012-05-13 23:56:07 -0700 | [diff] [blame] | 78 | static jclass shortClass; |
| 79 | static jclass socketClass; |
| 80 | static jclass socketImplClass; |
Yi Kong | 65eaf99 | 2016-04-01 14:53:42 +0100 | [diff] [blame^] | 81 | static jclass socketTaggerClass; |
Brian Carlstrom | dd8af23 | 2012-05-13 23:56:07 -0700 | [diff] [blame] | 82 | static jclass stringClass; |
| 83 | static jclass structAddrinfoClass; |
| 84 | static jclass structFlockClass; |
| 85 | static jclass structGroupReqClass; |
Neil Fuller | 11d09c7 | 2014-02-06 10:58:49 +0000 | [diff] [blame] | 86 | static jclass structGroupSourceReqClass; |
Brian Carlstrom | dd8af23 | 2012-05-13 23:56:07 -0700 | [diff] [blame] | 87 | static jclass structLingerClass; |
| 88 | static jclass structPasswdClass; |
| 89 | static jclass structPollfdClass; |
| 90 | static jclass structStatClass; |
Elliott Hughes | 47a1f29 | 2013-07-09 13:59:11 -0700 | [diff] [blame] | 91 | static jclass structStatVfsClass; |
Brian Carlstrom | dd8af23 | 2012-05-13 23:56:07 -0700 | [diff] [blame] | 92 | static jclass structTimevalClass; |
Elliott Hughes | 95b0038 | 2013-03-21 12:08:11 -0700 | [diff] [blame] | 93 | static jclass structUcredClass; |
Brian Carlstrom | dd8af23 | 2012-05-13 23:56:07 -0700 | [diff] [blame] | 94 | static jclass structUtsnameClass; |
Neil Fuller | 4ebb967 | 2015-07-07 17:00:21 +0100 | [diff] [blame] | 95 | static jclass unixSocketAddressClass; |
Narayan Kamath | b926f19 | 2015-01-08 18:37:52 +0000 | [diff] [blame] | 96 | static jclass zipEntryClass; |
Brian Carlstrom | dd8af23 | 2012-05-13 23:56:07 -0700 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | #define NATIVE_METHOD(className, functionName, signature) \ |
| 100 | { #functionName, signature, reinterpret_cast<void*>(className ## _ ## functionName) } |
| 101 | |
| 102 | #endif // JNI_CONSTANTS_H_included |