Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

dalvik: Commit

dalvik


Commit MetaInfo

Revisionca4fd209d67b9e783f7ad8a1512aa85aa2aba083 (tree)
Time2010-11-12 18:09:02
AuthorJim Huang <jserv@0xla...>
CommiterChih-Wei Huang

Log Message

Use GCC visibility to reduce the size of libdvm by 10%

Originally, libdvm exports many ELF symbols, but Zygote and other
applications don't really depend on all of them. This change hides
most of the symbols which would have previously (and unnecessarily)
been public. This means, it improves load time of libdvm, and the
link optimizer could produce better code as well.

The technique is applied in the "Performance" profile.

Reference experimental results of Qualcomm MSM7x25: (524 MHz)

[before]
(1) number of ELF symbols (when WITH_JIT=true)

# arm-eabi-nm --dynamic ./system/lib/libdvm.so | grep "T " | wc -l
1222

(2) dlopen/dlsym time

76906 us

(3) code size

./system/lib/libdvm.so 601480 bytes

[after]
(1) number of ELF symbols (when WITH_JIT=true)

# arm-eabi-nm --dynamic ./system/lib/libdvm.so | grep "T " | wc -l
58

(2) dlopen/dlsym time

72296 us

(3) code size

./system/lib/libdvm.so 540016 bytes

* dlopen/dlsym time: the time consumption from dlopen "libdvm" to

dlsym "dvmPrepForDexOpt"

Change-Id: I47fcf0da1acd970ff136378661360d3328c9c6c0

Change Summary

Incremental Difference

--- /dev/null
+++ b/dalvikdefines.h
@@ -0,0 +1,36 @@
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+ * Dalvik implementation specific definitions.
18+ */
19+
20+#ifndef _DALVIK_DEFINES_H
21+#define _DALVIK_DEFINES_H
22+
23+#if defined(ANDROID)
24+
25+/* Use GCC visibility */
26+#define DVM_EXPORT __attribute__((visibility("default")))
27+#define DEX_EXPORT DVM_EXPORT
28+
29+#else
30+
31+#define DVM_EXPORT
32+#define DEX_EXPORT
33+
34+#endif
35+
36+#endif /* ! _DALVIK_DEFINES_H */
--- a/libdex/Android.mk
+++ b/libdex/Android.mk
@@ -44,8 +44,25 @@ dex_include_files := \
4444 ifneq ($(SDK_ONLY),true) # SDK_only doesn't need device version
4545
4646 include $(CLEAR_VARS)
47+
48+# Make a debugging version when building the simulator (if not told
49+# otherwise) and when explicitly asked.
50+dvm_make_debug_vm := false
51+ifeq ($(strip $(DEBUG_DALVIK_VM)),)
52+ ifeq ($(dvm_simulator),true)
53+ dvm_make_debug_vm := true
54+ endif
55+else
56+ dvm_make_debug_vm := $(DEBUG_DALVIK_VM)
57+endif
58+
4759 LOCAL_SRC_FILES := $(dex_src_files)
4860 LOCAL_C_INCLUDES += $(dex_include_files)
61+LOCAL_CFLAGS += -include "dalvikdefines.h"
62+ifeq ($(dvm_make_debug_vm),false)
63+ # hide ELF symbols to reduce code size
64+ LOCAL_CFLAGS += -fvisibility=hidden
65+endif
4966 LOCAL_MODULE := libdex
5067 include $(BUILD_STATIC_LIBRARY)
5168
@@ -60,5 +77,6 @@ endif # !SDK_ONLY
6077 include $(CLEAR_VARS)
6178 LOCAL_SRC_FILES := $(dex_src_files)
6279 LOCAL_C_INCLUDES += $(dex_include_files)
80+LOCAL_CFLAGS += -include "dalvikdefines.h"
6381 LOCAL_MODULE := libdex
6482 include $(BUILD_HOST_STATIC_LIBRARY)
--- a/libdex/OptInvocation.c
+++ b/libdex/OptInvocation.c
@@ -116,6 +116,7 @@ char* dexOptGenerateCacheFileName(const char* fileName, const char* subFileName)
116116 *
117117 * Returns 0 on success, errno on failure.
118118 */
119+DEX_EXPORT
119120 int dexOptCreateEmptyHeader(int fd)
120121 {
121122 DexOptHeader optHdr;
--- a/libdex/ZipArchive.c
+++ b/libdex/ZipArchive.c
@@ -300,6 +300,7 @@ int dexZipOpenArchive(const char* fileName, ZipArchive* pArchive)
300300 /*
301301 * Prepare to access a ZipArchive in an open file descriptor.
302302 */
303+DEX_EXPORT
303304 int dexZipPrepArchive(int fd, const char* debugFileName, ZipArchive* pArchive)
304305 {
305306 MemMapping map;
@@ -347,6 +348,7 @@ bail:
347348 *
348349 * NOTE: the ZipArchive may not have been fully created.
349350 */
351+DEX_EXPORT
350352 void dexZipCloseArchive(ZipArchive* pArchive)
351353 {
352354 LOGV("Closing archive %p\n", pArchive);
@@ -370,6 +372,7 @@ void dexZipCloseArchive(ZipArchive* pArchive)
370372 *
371373 * Returns 0 if not found.
372374 */
375+DEX_EXPORT
373376 ZipEntry dexZipFindEntry(const ZipArchive* pArchive, const char* entryName)
374377 {
375378 int nameLen = strlen(entryName);
@@ -424,6 +427,7 @@ ZipEntry findEntryByIndex(ZipArchive* pArchive, int idx)
424427 * Returns "false" if the offsets to the fields or the contents of the fields
425428 * appear to be bogus.
426429 */
430+DEX_EXPORT
427431 bool dexZipGetEntryInfo(const ZipArchive* pArchive, ZipEntry entry,
428432 int* pMethod, long* pUncompLen, long* pCompLen, off_t* pOffset,
429433 long* pModWhen, long* pCrc32)
@@ -599,6 +603,7 @@ bail:
599603 * TODO: this doesn't verify the data's CRC, but probably should (especially
600604 * for uncompressed data).
601605 */
606+DEX_EXPORT
602607 bool dexZipExtractEntryToFile(const ZipArchive* pArchive,
603608 const ZipEntry entry, int fd)
604609 {
--- a/vm/Dvm.mk
+++ b/vm/Dvm.mk
@@ -26,6 +26,7 @@
2626 #
2727 LOCAL_CFLAGS += -fstrict-aliasing -Wstrict-aliasing=2 -fno-align-jumps
2828 #LOCAL_CFLAGS += -DUSE_INDIRECT_REF
29+LOCAL_CFLAGS += -include "dalvikdefines.h"
2930
3031 #
3132 # Optional features. These may impact the size or performance of the VM.
@@ -64,6 +65,7 @@ ifeq ($(dvm_make_debug_vm),true)
6465 # - GDB helpers enabled
6566 # - LOGV
6667 # - assert()
68+ # - full ELF symbols
6769 #
6870 LOCAL_CFLAGS += -DWITH_INSTR_CHECKS
6971 LOCAL_CFLAGS += -DWITH_EXTRA_OBJECT_VALIDATION
@@ -83,6 +85,7 @@ else # !dvm_make_debug_vm
8385 # - all development features disabled
8486 # - compiler optimizations enabled (redundant for "release" builds)
8587 # - (debugging and profiling still enabled)
88+ # - minimize ELF symbols to reduce code size by 10%
8689 #
8790 #LOCAL_CFLAGS += -DNDEBUG -DLOG_NDEBUG=1
8891 # "-O2" is redundant for device (release) but useful for sim (debug)
@@ -91,6 +94,8 @@ else # !dvm_make_debug_vm
9194 LOCAL_CFLAGS += -DDVM_SHOW_EXCEPTION=1
9295 # if you want to try with assertions on the device, add:
9396 #LOCAL_CFLAGS += -UNDEBUG -DDEBUG=1 -DLOG_NDEBUG=1 -DWITH_DALVIK_ASSERT
97+ # use GCC Visibility to reduce the footprint of runtime library
98+ LOCAL_CFLAGS += -fvisibility=hidden
9499 endif # !dvm_make_debug_vm
95100
96101 # bug hunting: checksum and verify interpreted stack when making JNI calls
--- a/vm/Init.c
+++ b/vm/Init.c
@@ -1491,6 +1491,7 @@ static bool dvmInitJDWP(void)
14911491 *
14921492 * Returns 0 on success.
14931493 */
1494+DVM_EXPORT
14941495 int dvmPrepForDexOpt(const char* bootClassPath, DexOptimizerMode dexOptMode,
14951496 DexClassVerifyMode verifyMode, int dexoptFlags)
14961497 {
--- a/vm/Jni.c
+++ b/vm/Jni.c
@@ -4255,6 +4255,7 @@ void dvmLateEnableCheckedJni(void)
42554255 /*
42564256 * Not supported.
42574257 */
4258+DVM_EXPORT
42584259 jint JNI_GetDefaultJavaVMInitArgs(void* vm_args)
42594260 {
42604261 return JNI_ERR;
@@ -4265,6 +4266,7 @@ jint JNI_GetDefaultJavaVMInitArgs(void* vm_args)
42654266 *
42664267 * We always have zero or one.
42674268 */
4269+DVM_EXPORT
42684270 jint JNI_GetCreatedJavaVMs(JavaVM** vmBuf, jsize bufLen, jsize* nVMs)
42694271 {
42704272 if (gDvm.vmList != NULL) {
@@ -4286,6 +4288,7 @@ jint JNI_GetCreatedJavaVMs(JavaVM** vmBuf, jsize bufLen, jsize* nVMs)
42864288 * The current thread becomes the main VM thread. We return immediately,
42874289 * which effectively means the caller is executing in a native method.
42884290 */
4291+DVM_EXPORT
42894292 jint JNI_CreateJavaVM(JavaVM** p_vm, JNIEnv** p_env, void* vm_args)
42904293 {
42914294 const JavaVMInitArgs* args = (JavaVMInitArgs*) vm_args;
--- a/vm/analysis/DexOptimize.c
+++ b/vm/analysis/DexOptimize.c
@@ -508,6 +508,7 @@ bool dvmOptimizeDexFile(int fd, off_t dexOffset, long dexLength,
508508 *
509509 * Returns "true" on success.
510510 */
511+DVM_EXPORT
511512 bool dvmContinueOptimization(int fd, off_t dexOffset, long dexLength,
512513 const char* fileName, u4 modWhen, u4 crc, bool isBootstrap)
513514 {
Show on old repository browser