react-native/React/Profiler/RCTProfileTrampoline-arm.S

110 lines
2.9 KiB
ArmAsm
Raw Normal View History

Refactored module access to allow for lazy loading Summary: public The `bridge.modules` dictionary provides access to all native modules, but this API requires that every module is initialized in advance so that any module can be accessed. This diff introduces a better API that will allow modules to be initialized lazily as they are needed, and deprecates `bridge.modules` (modules that use it will still work, but should be rewritten to use `bridge.moduleClasses` or `-[bridge moduleForName/Class:` instead. The rules are now as follows: * Any module that overrides `init` or `setBridge:` will be initialized on the main thread when the bridge is created * Any module that implements `constantsToExport:` will be initialized later when the config is exported (the module itself will be initialized on a background queue, but `constantsToExport:` will still be called on the main thread. * All other modules will be initialized lazily when a method is first called on them. These rules may seem slightly arcane, but they have the advantage of not violating any assumptions that may have been made by existing code - any module written under the original assumption that it would be initialized synchronously on the main thread when the bridge is created should still function exactly the same, but modules that avoid overriding `init` or `setBridge:` will now be loaded lazily. I've rewritten most of the standard modules to take advantage of this new lazy loading, with the following results: Out of the 65 modules included in UIExplorer: * 16 are initialized on the main thread when the bridge is created * A further 8 are initialized when the config is exported to JS * The remaining 41 will be initialized lazily on-demand Reviewed By: jspahrsummers Differential Revision: D2677695 fb-gh-sync-id: 507ae7e9fd6b563e89292c7371767c978e928f33
2015-11-25 11:09:00 +00:00
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include "RCTDefines.h"
#include "RCTMacros.h"
#if RCT_DEV && defined(__arm__)
.thumb
.thumb_func
.globl SYMBOL_NAME(RCTProfileTrampoline)
SYMBOL_NAME(RCTProfileTrampoline):
/**
* The explanation here is shorter, refer to the x86_64 implementation to a
* richer explanation
*/
/**
* Save the parameter registers (r0-r3), r7 (frame pointer) and lr (link
* register (contains the address of the caller of RCTProfileTrampoline)
*/
push {r0-r3, r7, lr}
/**
* Allocate memory to store values across function calls: 12-bytes are
* allocated to store 3 values: the previous value of the callee saved
* register used to save the pointer to the allocated memory, the caller of
* RCTProfileTrampoline and the address of the actual function we want to
* profile
*/
mov r0, #0xc
ldr ip, =L_malloc
ldr ip, [ip]
blx ip
/**
* r4 is the callee saved register we'll use to refer to the allocated memory,
* store its initial value, so we can restore it later
*/
str r4, [r0]
mov r4, r0
/**
* void RCTProfileGetImplementation(id object, SEL selector) in RCTProfile.m
*
* Load the first 2 argumenters (self and _cmd) used to call
* RCTProfileTrampoline from the stack and put them on the appropriate registers.
*/
ldr r0, [sp]
ldr r1, [sp, #0x4]
bl SYMBOL_NAME(RCTProfileGetImplementation)
// store the actual function address in the allocated memory
str r0, [r4, #0x4]
/**
* void RCTProfileGetImplementation(id object, SEL selector) in RCTProfile.m
*
* Load the first 2 arguments again to start the profiler
*/
ldr r0, [sp]
ldr r1, [sp, #0x4]
bl SYMBOL_NAME(RCTProfileTrampolineStart)
/**
* Restore the state to call the actual function we want to profile: pop
* all the registers
*/
pop {r0-r3, r7, lr}
// store lr (the caller) since it'll be overridden by `blx` (call)
str lr, [r4, #0x8]
ldr r12, [r4, #0x4] // load the function address
blx r12 // call it
push {r0} // save return value
// void RCTProfileTrampolineEnd(void) in RCTProfile.m - just ends this profile
bl SYMBOL_NAME(RCTProfileTrampolineEnd)
/**
* Save the value we still need from the allocated memory (caller address),
* restore r4 and free the allocated memory (put its address in r0)
*/
mov r0, r4
ldr r1, [r4, #0x8]
ldr r4, [r4]
push {r1} // save the caller on the stack
ldr ip, =L_free
ldr ip, [ip]
blx ip
pop {lr} // pop the caller
pop {r0} // pop the return value
bx lr // jump to the calleer
trap
.data
.p2align 2
L_malloc:
.long SYMBOL_NAME(malloc)
L_free:
.long SYMBOL_NAME(free)
#endif