2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef JNI_CONSTANTS_H_included
18 #define JNI_CONSTANTS_H_included
23 * A cache to avoid calling FindClass at runtime.
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 VM 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.
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.
38 * TODO: similar arguments hold for field and method IDs; we should cache them centrally too.
41 static void init(JNIEnv* env);
43 static jclass inet6AddressClass;
44 static jclass inetAddressClass;
45 static jclass inetSocketAddressClass;
46 static jclass stringClass;
49 #define NATIVE_METHOD(className, functionName, signature) \
50 { #functionName, signature, reinterpret_cast<void*>(className ## _ ## functionName) }
52 #endif // JNI_CONSTANTS_H_included