Changeset 232936 in webkit


Ignore:
Timestamp:
Jun 18, 2018 11:49:01 AM (6 years ago)
Author:
commit-queue@webkit.org
Message:

Share structure across instances of classes exported through the ObjC API
https://bugs.webkit.org/show_bug.cgi?id=186579
<rdar://problem/40969212>

Patch by Tadeu Zagallo <Tadeu Zagallo> on 2018-06-18
Reviewed by Saam Barati.

A new structure was being created for each instance of exported ObjC
classes due to setting the prototype in the structure for every object,
since prototype transitions are not cached by the structure. Cache the
Structure in the JSObjcClassInfo to avoid the transition.

  • API/JSWrapperMap.mm:

(-[JSObjCClassInfo wrapperForObject:inContext:]):
(-[JSObjCClassInfo structureInContext:]):

  • API/tests/JSWrapperMapTests.h: Added.
  • API/tests/JSWrapperMapTests.mm: Added.

(+[JSWrapperMapTests testStructureIdentity]):
(runJSWrapperMapTests):

  • API/tests/testapi.mm:

(testObjectiveCAPIMain):

Location:
trunk/Source/JavaScriptCore
Files:
2 added
4 edited

Legend:

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

    r229410 r232936  
    368368    JSC::Weak<JSC::JSObject> m_prototype;
    369369    JSC::Weak<JSC::JSObject> m_constructor;
     370    JSC::Weak<JSC::Structure> m_structure;
    370371}
    371372
     
    518519    }
    519520
    520     JSC::JSObject* prototype = [self prototypeInContext:context];
    521 
    522     JSC::JSObject* wrapper = makeWrapper([context JSGlobalContextRef], m_classRef, object);
    523     JSObjectSetPrototype([context JSGlobalContextRef], toRef(wrapper), toRef(prototype));
     521    JSC::Structure* structure = [self structureInContext:context];
     522
     523    JSC::ExecState* exec = toJS([context JSGlobalContextRef]);
     524    JSC::VM& vm = exec->vm();
     525    JSC::JSLockHolder locker(vm);
     526
     527    JSC::JSCallbackObject<JSC::JSAPIWrapperObject>* wrapper = JSC::JSCallbackObject<JSC::JSAPIWrapperObject>::create(exec, exec->lexicalGlobalObject(), structure, m_classRef, 0);
     528    wrapper->setWrappedObject(object);
    524529    return wrapper;
    525530}
     
    541546    ASSERT(!!prototype);
    542547    return prototype;
     548}
     549
     550- (JSC::Structure*)structureInContext:(JSContext *)context
     551{
     552    JSC::Structure* structure = m_structure.get();
     553    if (structure)
     554        return structure;
     555
     556    JSC::ExecState* exec = toJS([context JSGlobalContextRef]);
     557    JSC::JSGlobalObject* globalObject = toJSGlobalObject([context JSGlobalContextRef]);
     558    JSC::JSObject* prototype = [self prototypeInContext:context];
     559    m_structure = JSC::JSCallbackObject<JSC::JSAPIWrapperObject>::createStructure(exec->vm(), globalObject, prototype);
     560
     561    return m_structure.get();
    543562}
    544563
  • trunk/Source/JavaScriptCore/API/tests/testapi.mm

    r231938 r232936  
    3030#import "JSExportTests.h"
    3131#import "JSVirtualMachinePrivate.h"
     32#import "JSWrapperMapTests.h"
    3233#import "Regress141275.h"
    3334#import "Regress141809.h"
     
    14761477    runDateTests();
    14771478    runJSExportTests();
     1479    runJSWrapperMapTests();
    14781480    runRegress141275();
    14791481    runRegress141809();
  • trunk/Source/JavaScriptCore/ChangeLog

    r232934 r232936  
     12018-06-18  Tadeu Zagallo  <tzagallo@apple.com>
     2
     3        Share structure across instances of classes exported through the ObjC API
     4        https://bugs.webkit.org/show_bug.cgi?id=186579
     5        <rdar://problem/40969212>
     6
     7        Reviewed by Saam Barati.
     8
     9        A new structure was being created for each instance of exported ObjC
     10        classes due to setting the prototype in the structure for every object,
     11        since prototype transitions are not cached by the structure. Cache the
     12        Structure in the JSObjcClassInfo to avoid the transition.
     13
     14        * API/JSWrapperMap.mm:
     15        (-[JSObjCClassInfo wrapperForObject:inContext:]):
     16        (-[JSObjCClassInfo structureInContext:]):
     17        * API/tests/JSWrapperMapTests.h: Added.
     18        * API/tests/JSWrapperMapTests.mm: Added.
     19        (+[JSWrapperMapTests testStructureIdentity]):
     20        (runJSWrapperMapTests):
     21        * API/tests/testapi.mm:
     22        (testObjectiveCAPIMain):
     23        * JavaScriptCore.xcodeproj/project.pbxproj:
     24
    1252018-06-18  Michael Saboff  <msaboff@apple.com>
    226
  • trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r232664 r232936  
    763763                144836E7132DA7BE005BE785 /* ConservativeRoots.h in Headers */ = {isa = PBXBuildFile; fileRef = 149DAAF212EB559D0083B12B /* ConservativeRoots.h */; settings = {ATTRIBUTES = (Private, ); }; };
    764764                145722861437E140005FDE26 /* StrongInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 145722851437E140005FDE26 /* StrongInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
     765                1471483020D323D30090E630 /* JSWrapperMapTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1471482F20D323650090E630 /* JSWrapperMapTests.mm */; };
    765766                147341CC1DC02D7200AA29BA /* ExecutableBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 147341CB1DC02D7200AA29BA /* ExecutableBase.h */; settings = {ATTRIBUTES = (Private, ); }; };
    766767                147341CE1DC02D7900AA29BA /* ScriptExecutable.h in Headers */ = {isa = PBXBuildFile; fileRef = 147341CD1DC02D7900AA29BA /* ScriptExecutable.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    30843085                146FA5A81378F6B0003627A3 /* HandleTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HandleTypes.h; sourceTree = "<group>"; };
    30853086                146FE51111A710430087AE66 /* JITCall32_64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JITCall32_64.cpp; sourceTree = "<group>"; };
     3087                1471482E20D323640090E630 /* JSWrapperMapTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSWrapperMapTests.h; path = API/tests/JSWrapperMapTests.h; sourceTree = "<group>"; };
     3088                1471482F20D323650090E630 /* JSWrapperMapTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = JSWrapperMapTests.mm; path = API/tests/JSWrapperMapTests.mm; sourceTree = "<group>"; };
    30863089                147341CB1DC02D7200AA29BA /* ExecutableBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExecutableBase.h; sourceTree = "<group>"; };
    30873090                147341CD1DC02D7900AA29BA /* ScriptExecutable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptExecutable.h; sourceTree = "<group>"; };
     
    54335436                                5C4E8E941DBEBDA20036F1FC /* JSONParseTest.cpp */,
    54345437                                5C4E8E951DBEBDA20036F1FC /* JSONParseTest.h */,
     5438                                1471482E20D323640090E630 /* JSWrapperMapTests.h */,
     5439                                1471482F20D323650090E630 /* JSWrapperMapTests.mm */,
    54355440                                144005170A531CB50005F061 /* minidom */,
    54365441                                FEF49AA91EB947FE00653BDB /* MultithreadedMultiVMExecutionTest.cpp */,
     
    1015510160                                0FF47C5A1EBFE84600F280B7 /* JSObjectGetProxyTargetTest.cpp in Sources */,
    1015610161                                5C4E8E961DBEBE620036F1FC /* JSONParseTest.cpp in Sources */,
     10162                                1471483020D323D30090E630 /* JSWrapperMapTests.mm in Sources */,
    1015710163                                FEF49AAB1EB9484B00653BDB /* MultithreadedMultiVMExecutionTest.cpp in Sources */,
    1015810164                                FE7C41961B97FC4B00F4D598 /* PingPongStackOverflowTest.cpp in Sources */,
Note: See TracChangeset for help on using the changeset viewer.