Ignore:
Timestamp:
Sep 3, 2014, 2:01:43 PM (11 years ago)
Author:
[email protected]
Message:

Create tests for type profiling
https://bugs.webkit.org/show_bug.cgi?id=136161

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

The type profiler is now being tested. These are basic tests that don't
check every edge case, but will catch any major failures in the type profiler.
These tests cover:

  • The basic, inheritance-based type system in TypeSet.
  • Function return types.
  • Correct merging of types for multiple assignments to one variable.

This patch also provides an API for writing new tests for
the type profiler. The API works by passing in a function and a
unique substring of an expression contained in that function, and
returns an object representing type information for that expression.

  • jsc.cpp:

(GlobalObject::finishCreation):
(functionFindTypeForExpression):
(functionReturnTypeFor):

  • runtime/TypeProfiler.cpp:

(JSC::TypeProfiler::typeInformationForExpressionAtOffset):

  • runtime/TypeProfiler.h:
  • runtime/TypeProfilerLog.h:
  • runtime/TypeSet.cpp:

(JSC::TypeSet::toJSONString):
(JSC::StructureShape::toJSONString):

  • runtime/TypeSet.h:
  • tests/typeProfiler: Added.
  • tests/typeProfiler.yaml: Added.
  • tests/typeProfiler/basic.js: Added.

(wrapper.foo):
(wrapper):

  • tests/typeProfiler/captured.js: Added.

(wrapper.changeFoo):
(wrapper):

  • tests/typeProfiler/driver: Added.
  • tests/typeProfiler/driver/driver.js: Added.

(assert):

  • tests/typeProfiler/inheritance.js: Added.

(wrapper.A):
(wrapper.B):
(wrapper.C):
(wrapper):

  • tests/typeProfiler/return.js: Added.

(foo):
(Ctor):

Tools:

Have run-javascriptcore-tests run the newly created
tests for the type profiler.

  • Scripts/run-javascriptcore-tests:
  • Scripts/run-jsc-stress-tests:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/jsc.cpp

    r173120 r173225  
    3838#include "JSFunction.h"
    3939#include "JSLock.h"
     40#include "JSONObject.h"
    4041#include "JSProxy.h"
    4142#include "JSString.h"
     
    4647#include "StructureRareDataInlines.h"
    4748#include "TestRunnerUtils.h"
     49#include "TypeProfilerLog.h"
    4850#include <math.h>
    4951#include <stdio.h>
     
    477479static EncodedJSValue JSC_HOST_CALL functionMakeMasquerader(ExecState*);
    478480static EncodedJSValue JSC_HOST_CALL functionHasCustomProperties(ExecState*);
    479 static EncodedJSValue JSC_HOST_CALL functionDumpTypesForAllVariables (ExecState*);
     481static EncodedJSValue JSC_HOST_CALL functionDumpTypesForAllVariables(ExecState*);
     482static EncodedJSValue JSC_HOST_CALL functionFindTypeForExpression(ExecState*);
     483static EncodedJSValue JSC_HOST_CALL functionReturnTypeFor(ExecState*);
    480484
    481485#if ENABLE(SAMPLING_FLAGS)
     
    628632        addFunction(vm, "createImpureGetter", functionCreateImpureGetter, 1);
    629633        addFunction(vm, "setImpureGetterDelegate", functionSetImpureGetterDelegate, 2);
    630         addFunction(vm, "dumpTypesForAllVariables", functionDumpTypesForAllVariables , 4);
     634
     635        addFunction(vm, "dumpTypesForAllVariables", functionDumpTypesForAllVariables , 0);
     636        addFunction(vm, "findTypeForExpression", functionFindTypeForExpression, 2);
     637        addFunction(vm, "returnTypeFor", functionReturnTypeFor, 1);
    631638       
    632639        JSArray* array = constructEmptyArray(globalExec(), 0);
     
    10641071    exec->vm().dumpTypeProfilerData();
    10651072    return JSValue::encode(jsUndefined());
     1073}
     1074
     1075EncodedJSValue JSC_HOST_CALL functionFindTypeForExpression(ExecState* exec)
     1076{
     1077    RELEASE_ASSERT(exec->vm().typeProfiler());
     1078    exec->vm().typeProfilerLog()->processLogEntries(ASCIILiteral("jsc Testing API: functionFindTypeForExpression"));
     1079
     1080    JSValue functionValue = exec->argument(0);
     1081    RELEASE_ASSERT(functionValue.isFunction());
     1082    FunctionExecutable* executable = (jsDynamicCast<JSFunction*>(functionValue.asCell()->getObject()))->jsExecutable();
     1083
     1084    RELEASE_ASSERT(exec->argument(1).isString());
     1085    String substring = exec->argument(1).getString(exec);
     1086    String sourceCodeText = executable->source().toString();
     1087    unsigned offset = static_cast<unsigned>(sourceCodeText.find(substring) + executable->source().startOffset());
     1088   
     1089    String jsonString = exec->vm().typeProfiler()->typeInformationForExpressionAtOffset(TypeProfilerSearchDescriptorNormal, offset, executable->sourceID());
     1090    return JSValue::encode(JSONParse(exec, jsonString));
     1091}
     1092
     1093EncodedJSValue JSC_HOST_CALL functionReturnTypeFor(ExecState* exec)
     1094{
     1095    RELEASE_ASSERT(exec->vm().typeProfiler());
     1096    exec->vm().typeProfilerLog()->processLogEntries(ASCIILiteral("jsc Testing API: functionReturnTypeFor"));
     1097
     1098    JSValue functionValue = exec->argument(0);
     1099    RELEASE_ASSERT(functionValue.isFunction());
     1100    FunctionExecutable* executable = (jsDynamicCast<JSFunction*>(functionValue.asCell()->getObject()))->jsExecutable();
     1101
     1102    unsigned offset = executable->source().startOffset();
     1103    String jsonString = exec->vm().typeProfiler()->typeInformationForExpressionAtOffset(TypeProfilerSearchDescriptorFunctionReturn, offset, executable->sourceID());
     1104    return JSValue::encode(JSONParse(exec, jsonString));
    10661105}
    10671106
Note: See TracChangeset for help on using the changeset viewer.