blob: a3d917f733430ec6b2b0b1a35a2fbf31da51c63b [file] [log] [blame]
Brian Carlstromdd8af232012-05-13 23:56:07 -07001/*
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 Colitti63daad52015-03-12 01:22:36 +090025 * 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 Carlstromdd8af232012-05-13 23:56:07 -070029 * 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 */
39struct JniConstants {
40 static void init(JNIEnv* env);
41
Brian Carlstromdd8af232012-05-13 23:56:07 -070042 static jclass booleanClass;
43 static jclass byteArrayClass;
Kenny Rootf4a3c1e2013-03-07 11:20:28 -080044 static jclass calendarClass;
Brian Carlstromdd8af232012-05-13 23:56:07 -070045 static jclass charsetICUClass;
Brian Carlstromdd8af232012-05-13 23:56:07 -070046 static jclass doubleClass;
47 static jclass errnoExceptionClass;
Brian Carlstromdd8af232012-05-13 23:56:07 -070048 static jclass fileDescriptorClass;
Brian Carlstromdd8af232012-05-13 23:56:07 -070049 static jclass gaiExceptionClass;
50 static jclass inet6AddressClass;
Yi Kongc9be4672016-07-11 00:07:32 +010051 static jclass inet6AddressHolderClass;
Brian Carlstromdd8af232012-05-13 23:56:07 -070052 static jclass inetAddressClass;
Piotr Jastrzebski6ea79a12015-05-06 14:00:36 +010053 static jclass inetAddressHolderClass;
Brian Carlstromdd8af232012-05-13 23:56:07 -070054 static jclass inetSocketAddressClass;
Piotr Jastrzebski75fc6d22015-06-02 10:58:22 +010055 static jclass inetSocketAddressHolderClass;
Brian Carlstromdd8af232012-05-13 23:56:07 -070056 static jclass integerClass;
57 static jclass localeDataClass;
58 static jclass longClass;
Erik Kline25b67b12015-02-25 18:33:29 +090059 static jclass netlinkSocketAddressClass;
Lorenzo Colitti63daad52015-03-12 01:22:36 +090060 static jclass packetSocketAddressClass;
Brian Carlstromdd8af232012-05-13 23:56:07 -070061 static jclass patternSyntaxExceptionClass;
Jeff Browndc176c52013-04-02 18:09:29 -070062 static jclass referenceClass;
Yi Kong65eaf992016-04-01 14:53:42 +010063 static jclass socketTaggerClass;
Brian Carlstromdd8af232012-05-13 23:56:07 -070064 static jclass stringClass;
65 static jclass structAddrinfoClass;
66 static jclass structFlockClass;
67 static jclass structGroupReqClass;
Yi Konge26fd492016-06-08 15:23:53 +020068 static jclass structIfaddrs;
Brian Carlstromdd8af232012-05-13 23:56:07 -070069 static jclass structLingerClass;
70 static jclass structPasswdClass;
71 static jclass structPollfdClass;
72 static jclass structStatClass;
Elliott Hughes47a1f292013-07-09 13:59:11 -070073 static jclass structStatVfsClass;
Brian Carlstromdd8af232012-05-13 23:56:07 -070074 static jclass structTimevalClass;
Przemyslaw Szczepaniak5f724722017-07-13 14:24:52 +010075 static jclass structTimespecClass;
Elliott Hughes95b00382013-03-21 12:08:11 -070076 static jclass structUcredClass;
Brian Carlstromdd8af232012-05-13 23:56:07 -070077 static jclass structUtsnameClass;
Neil Fuller4ebb9672015-07-07 17:00:21 +010078 static jclass unixSocketAddressClass;
Narayan Kamathb926f192015-01-08 18:37:52 +000079 static jclass zipEntryClass;
Brian Carlstromdd8af232012-05-13 23:56:07 -070080};
81
82#define NATIVE_METHOD(className, functionName, signature) \
83 { #functionName, signature, reinterpret_cast<void*>(className ## _ ## functionName) }
84
85#endif // JNI_CONSTANTS_H_included