⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 254152 in webkit


Ignore:
Timestamp:
Jan 7, 2020, 1:13:23 PM (7 years ago)
Author:
ysuzuki@apple.com
Message:

[JSC] Remove vm accessor in JSVirtualMachine to reduce binary size
​https://bugs.webkit.org/show_bug.cgi?id=205880

Reviewed by Mark Lam.

Objective-C has reflection mechanism. This means that fields, methods, and their types
need to hold its string representations in binary even if we are using release build.
While typical Objective-C class does not have large size of type names, C++ struct / class
has very large one, and putting them in Objective-C method names, parameter types, or fields
makes binary size very large.

By analyzing JavaScriptCore binary, I found that Objective-C method type symbols are taking 200~KB
binary size. (Section objc_methtype: 235081 (addr 0x105e9a3 offset 17164707)). And it is due to
JSC::VM type included in [JSVirtualMachine vm] accessor.

This patch removes this accessor and gets 200KB binary size reduction.

  • API/JSScript.mm:

(-[JSScript readCache]):
(-[JSScript sourceCode]):
(-[JSScript jsSourceCode]):
(-[JSScript writeCache:]):

  • API/JSVirtualMachine.mm:

(-[JSVirtualMachine JSContextGroupRef]):
(-[JSVirtualMachine isWebThreadAware]):
(-[JSVirtualMachine vm]): Deleted.

  • API/JSVirtualMachineInternal.h:
Location:
trunk/Source/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/JSScript.mm

    r247542 r254152  
    168168    Ref<JSC::CachedBytecode> cachedBytecode = JSC::CachedBytecode::create(WTFMove(mappedFile));
    169169
    170     JSC::VM& vm = [m_virtualMachine vm];
     170    JSC::VM& vm = *toJS([m_virtualMachine JSContextGroupRef]);
    171171    JSC::SourceCode sourceCode = [self sourceCode];
    172172    JSC::SourceCodeKey key = m_type == kJSScriptTypeProgram ? sourceCodeKeyForSerializedProgram(vm, sourceCode) : sourceCodeKeyForSerializedModule(vm, sourceCode);
    … …  
    236236- (JSC::SourceCode)sourceCode
    237237{
    238     JSC::VM& vm = [m_virtualMachine vm];
     238    JSC::VM& vm = *toJS([m_virtualMachine JSContextGroupRef]);
    239239    JSC::JSLockHolder locker(vm);
    240240
    … …  
    249249- (JSC::JSSourceCode*)jsSourceCode
    250250{
    251     JSC::VM& vm = [m_virtualMachine vm];
     251    JSC::VM& vm = *toJS([m_virtualMachine JSContextGroupRef]);
    252252    JSC::JSLockHolder locker(vm);
    253253    JSC::JSSourceCode* jsSourceCode = JSC::JSSourceCode::create(vm, [self sourceCode]);
    … …  
    278278    JSC::BytecodeCacheError cacheError;
    279279    JSC::SourceCode sourceCode = [self sourceCode];
     280    JSC::VM& vm = *toJS([m_virtualMachine JSContextGroupRef]);
    280281    switch (m_type) {
    281282    case kJSScriptTypeModule:
    282         m_cachedBytecode = JSC::generateModuleBytecode([m_virtualMachine vm], sourceCode, fd, cacheError);
     283        m_cachedBytecode = JSC::generateModuleBytecode(vm, sourceCode, fd, cacheError);
    283284        break;
    284285    case kJSScriptTypeProgram:
    285         m_cachedBytecode = JSC::generateProgramBytecode([m_virtualMachine vm], sourceCode, fd, cacheError);
     286        m_cachedBytecode = JSC::generateProgramBytecode(vm, sourceCode, fd, cacheError);
    286287        break;
    287288    }
  • trunk/Source/JavaScriptCore/API/JSVirtualMachine.mm

    r249885 r254152  
    299299#endif // ENABLE(DFG_JIT)
    300300
    301 - (JSC::VM&)vm
    302 {
    303     return *toJS(m_group);
     301- (JSContextGroupRef)JSContextGroupRef
     302{
     303    return m_group;
    304304}
    305305
    306306- (BOOL)isWebThreadAware
    307307{
    308     return [self vm].apiLock().isWebThreadAware();
     308    JSC::VM* vm = toJS(m_group);
     309    return vm->apiLock().isWebThreadAware();
    309310}
    310311
  • trunk/Source/JavaScriptCore/API/JSVirtualMachineInternal.h

    r247346 r254152  
    4747- (JSContext *)contextForGlobalContextRef:(JSGlobalContextRef)globalContext;
    4848- (void)addContext:(JSContext *)wrapper forGlobalContextRef:(JSGlobalContextRef)globalContext;
    49 - (JSC::VM&)vm;
     49- (BOOL)isWebThreadAware;
    5050
    51 - (BOOL)isWebThreadAware;
     51@property (readonly) JSContextGroupRef JSContextGroupRef;
    5252
    5353@end
  • trunk/Source/JavaScriptCore/ChangeLog

    r254143 r254152  
     12020-01-07  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Remove vm accessor in JSVirtualMachine to reduce binary size
     4        https://bugs.webkit.org/show_bug.cgi?id=205880
     5
     6        Reviewed by Mark Lam.
     7
     8        Objective-C has reflection mechanism. This means that fields, methods, and their types
     9        need to hold its string representations in binary even if we are using release build.
     10        While typical Objective-C class does not have large size of type names, C++ struct / class
     11        has very large one, and putting them in Objective-C method names, parameter types, or fields
     12        makes binary size very large.
     13
     14        By analyzing JavaScriptCore binary, I found that Objective-C method type symbols are taking 200~KB
     15        binary size. (Section __objc_methtype: 235081 (addr 0x105e9a3 offset 17164707)). And it is due to
     16        JSC::VM type included in `[JSVirtualMachine vm]` accessor.
     17
     18        This patch removes this accessor and gets 200KB binary size reduction.
     19
     20        * API/JSScript.mm:
     21        (-[JSScript readCache]):
     22        (-[JSScript sourceCode]):
     23        (-[JSScript jsSourceCode]):
     24        (-[JSScript writeCache:]):
     25        * API/JSVirtualMachine.mm:
     26        (-[JSVirtualMachine JSContextGroupRef]):
     27        (-[JSVirtualMachine isWebThreadAware]):
     28        (-[JSVirtualMachine vm]): Deleted.
     29        * API/JSVirtualMachineInternal.h:
     30
    1312020-01-07  Keith Miller  <keith_miller@apple.com>
    232
Note: See TracChangeset for help on using the changeset viewer.