Changeset 196155 in webkit


Ignore:
Timestamp:
Feb 4, 2016 4:36:20 PM (8 years ago)
Author:
keith_miller@apple.com
Message:

ArrayPrototype should have a destroy function
https://bugs.webkit.org/show_bug.cgi?id=153847

Reviewed by Filip Pizlo.

ArrayPrototype should have an destroy function as it now has a unique_ptr member that
needs to be freed at the end of the object's life cycle. Also, this patch adds an
option, gcAtEnd, that will cause jsc.cpp to do a garbage collection before exiting.

  • jsc.cpp:

(runJSC):
(jscmain):

  • runtime/ArrayPrototype.cpp:

(JSC::ArrayPrototype::create):
(JSC::ArrayPrototype::destroy):

  • runtime/ArrayPrototype.h:
  • runtime/Options.h:
Location:
trunk/Source/JavaScriptCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r196152 r196155  
     12016-02-04  Keith Miller  <keith_miller@apple.com>
     2
     3        ArrayPrototype should have a destroy function
     4        https://bugs.webkit.org/show_bug.cgi?id=153847
     5
     6        Reviewed by Filip Pizlo.
     7
     8        ArrayPrototype should have an destroy function as it now has a unique_ptr member that
     9        needs to be freed at the end of the object's life cycle. Also, this patch adds an
     10        option, gcAtEnd, that will cause jsc.cpp to do a garbage collection before exiting.
     11
     12        * jsc.cpp:
     13        (runJSC):
     14        (jscmain):
     15        * runtime/ArrayPrototype.cpp:
     16        (JSC::ArrayPrototype::create):
     17        (JSC::ArrayPrototype::destroy):
     18        * runtime/ArrayPrototype.h:
     19        * runtime/Options.h:
     20
    1212016-02-04  Filip Pizlo  <fpizlo@apple.com>
    222
  • trunk/Source/JavaScriptCore/jsc.cpp

    r195916 r196155  
    20242024}
    20252025
     2026// We make this function no inline so that globalObject won't be on the stack if we do a GC in jscmain.
     2027static int NEVER_INLINE runJSC(VM* vm, CommandLine options)
     2028{
     2029    JSLockHolder locker(vm);
     2030
     2031    int result;
     2032    if (options.m_profile && !vm->m_perBytecodeProfiler)
     2033        vm->m_perBytecodeProfiler = std::make_unique<Profiler::Database>(*vm);
     2034
     2035    GlobalObject* globalObject = GlobalObject::create(*vm, GlobalObject::createStructure(*vm, jsNull()), options.m_arguments);
     2036    bool success = runWithScripts(globalObject, options.m_scripts, options.m_dump, options.m_module);
     2037    if (options.m_interactive && success)
     2038        runInteractive(globalObject);
     2039
     2040    result = success ? 0 : 3;
     2041
     2042    if (options.m_exitCode)
     2043        printf("jsc exiting %d\n", result);
     2044
     2045    if (options.m_profile) {
     2046        if (!vm->m_perBytecodeProfiler->save(options.m_profilerOutput.utf8().data()))
     2047            fprintf(stderr, "could not save profiler output.\n");
     2048    }
     2049
     2050#if ENABLE(JIT)
     2051    if (Options::useExceptionFuzz())
     2052        printf("JSC EXCEPTION FUZZ: encountered %u checks.\n", numberOfExceptionFuzzChecks());
     2053    bool fireAtEnabled =
     2054    Options::fireExecutableAllocationFuzzAt() || Options::fireExecutableAllocationFuzzAtOrAfter();
     2055    if (Options::useExecutableAllocationFuzz() && (!fireAtEnabled || Options::verboseExecutableAllocationFuzz()))
     2056        printf("JSC EXECUTABLE ALLOCATION FUZZ: encountered %u checks.\n", numberOfExecutableAllocationFuzzChecks());
     2057    if (Options::useOSRExitFuzz()) {
     2058        printf("JSC OSR EXIT FUZZ: encountered %u static checks.\n", numberOfStaticOSRExitFuzzChecks());
     2059        printf("JSC OSR EXIT FUZZ: encountered %u dynamic checks.\n", numberOfOSRExitFuzzChecks());
     2060    }
     2061#endif
     2062    auto compileTimeStats = DFG::Plan::compileTimeStats();
     2063    Vector<CString> compileTimeKeys;
     2064    for (auto& entry : compileTimeStats)
     2065        compileTimeKeys.append(entry.key);
     2066    std::sort(compileTimeKeys.begin(), compileTimeKeys.end());
     2067    for (CString key : compileTimeKeys)
     2068        printf("%40s: %.3lf ms\n", key.data(), compileTimeStats.get(key));
     2069
     2070    return result;
     2071}
     2072
    20262073int jscmain(int argc, char** argv)
    20272074{
     
    20382085    VM* vm = &VM::create(LargeHeap).leakRef();
    20392086    int result;
    2040     {
     2087    result = runJSC(vm, options);
     2088
     2089    if (Options::gcAtEnd()) {
     2090        // We need to hold the API lock to do a GC.
    20412091        JSLockHolder locker(vm);
    2042 
    2043         if (options.m_profile && !vm->m_perBytecodeProfiler)
    2044             vm->m_perBytecodeProfiler = std::make_unique<Profiler::Database>(*vm);
    2045    
    2046         GlobalObject* globalObject = GlobalObject::create(*vm, GlobalObject::createStructure(*vm, jsNull()), options.m_arguments);
    2047         bool success = runWithScripts(globalObject, options.m_scripts, options.m_dump, options.m_module);
    2048         if (options.m_interactive && success)
    2049             runInteractive(globalObject);
    2050 
    2051         result = success ? 0 : 3;
    2052 
    2053         if (options.m_exitCode)
    2054             printf("jsc exiting %d\n", result);
    2055    
    2056         if (options.m_profile) {
    2057             if (!vm->m_perBytecodeProfiler->save(options.m_profilerOutput.utf8().data()))
    2058                 fprintf(stderr, "could not save profiler output.\n");
    2059         }
    2060        
    2061 #if ENABLE(JIT)
    2062         if (Options::useExceptionFuzz())
    2063             printf("JSC EXCEPTION FUZZ: encountered %u checks.\n", numberOfExceptionFuzzChecks());
    2064         bool fireAtEnabled =
    2065             Options::fireExecutableAllocationFuzzAt() || Options::fireExecutableAllocationFuzzAtOrAfter();
    2066         if (Options::useExecutableAllocationFuzz() && (!fireAtEnabled || Options::verboseExecutableAllocationFuzz()))
    2067             printf("JSC EXECUTABLE ALLOCATION FUZZ: encountered %u checks.\n", numberOfExecutableAllocationFuzzChecks());
    2068         if (Options::useOSRExitFuzz()) {
    2069             printf("JSC OSR EXIT FUZZ: encountered %u static checks.\n", numberOfStaticOSRExitFuzzChecks());
    2070             printf("JSC OSR EXIT FUZZ: encountered %u dynamic checks.\n", numberOfOSRExitFuzzChecks());
    2071         }
    2072 #endif
    2073         auto compileTimeStats = DFG::Plan::compileTimeStats();
    2074         Vector<CString> compileTimeKeys;
    2075         for (auto& entry : compileTimeStats)
    2076             compileTimeKeys.append(entry.key);
    2077         std::sort(compileTimeKeys.begin(), compileTimeKeys.end());
    2078         for (CString key : compileTimeKeys)
    2079             printf("%40s: %.3lf ms\n", key.data(), compileTimeStats.get(key));
    2080     }
    2081    
     2092        vm->heap.collectAllGarbage();
     2093    }
     2094
    20822095    return result;
    20832096}
  • trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp

    r195878 r196155  
    7575    ArrayPrototype* prototype = new (NotNull, allocateCell<ArrayPrototype>(vm.heap)) ArrayPrototype(vm, structure);
    7676    prototype->finishCreation(vm, globalObject);
     77    vm.heap.addFinalizer(prototype, destroy);
    7778    return prototype;
    7879}
     
    139140}
    140141
     142void ArrayPrototype::destroy(JSC::JSCell* cell)
     143{
     144    ArrayPrototype* thisObject = static_cast<ArrayPrototype*>(cell);
     145    thisObject->ArrayPrototype::~ArrayPrototype();
     146}
     147
    141148// ------------------------------ Array Functions ----------------------------
    142149
  • trunk/Source/JavaScriptCore/runtime/ArrayPrototype.h

    r195878 r196155  
    4949    bool didChangeConstructorProperty() const { return m_didChangeConstructorProperty; }
    5050
     51    static const bool needsDestruction = false;
     52    // We don't need destruction since we use a finalizer.
     53    static void destroy(JSC::JSCell*);
     54
    5155protected:
    5256    void finishCreation(VM&, JSGlobalObject*);
  • trunk/Source/JavaScriptCore/runtime/Options.h

    r196044 r196155  
    320320    v(gcLogLevel, logGC, GCLogging::None, "debugging option to log GC activity (0 = None, 1 = Basic, 2 = Verbose)") \
    321321    v(bool, useGC, true, nullptr) \
     322    v(bool, gcAtEnd, false, "If true, the jsc CLI will do a GC before exiting") \
    322323    v(bool, forceGCSlowPaths, false, "If true, we will force all JIT fast allocations down their slow paths.")\
    323324    v(unsigned, gcMaxHeapSize, 0, nullptr) \
Note: See TracChangeset for help on using the changeset viewer.