2012-08-23 12:32:20 -07:00
|
|
|
/* -*- Mode: C++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil -*- */
|
|
|
|
/* vim: set ts=4 sw=4 et tw=99: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2010-11-01 20:03:46 -07:00
|
|
|
/* Inline members for javascript type inference. */
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2011-05-16 16:15:37 -07:00
|
|
|
#include "jsarray.h"
|
2010-10-29 08:05:55 -07:00
|
|
|
#include "jsanalyze.h"
|
|
|
|
#include "jscompartment.h"
|
|
|
|
#include "jsinfer.h"
|
2010-10-29 11:44:30 -07:00
|
|
|
#include "jsprf.h"
|
2012-05-01 14:30:18 -07:00
|
|
|
|
2012-11-06 10:50:19 -08:00
|
|
|
#ifdef JS_ION
|
2012-01-12 10:28:03 -08:00
|
|
|
#include "ion/IonFrames.h"
|
2012-11-06 10:50:19 -08:00
|
|
|
#endif
|
2013-03-12 14:05:57 -07:00
|
|
|
#include "js/RootingAPI.h"
|
|
|
|
#include "vm/GlobalObject.h"
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2011-06-05 22:39:45 -07:00
|
|
|
#include "vm/Stack-inl.h"
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
#ifndef jsinferinlines_h___
|
|
|
|
#define jsinferinlines_h___
|
|
|
|
|
2012-09-26 09:49:20 -07:00
|
|
|
inline bool
|
|
|
|
js::TaggedProto::isObject() const
|
|
|
|
{
|
|
|
|
/* Skip NULL and Proxy::LazyProto. */
|
|
|
|
return uintptr_t(proto) > uintptr_t(Proxy::LazyProto);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
js::TaggedProto::isLazy() const
|
|
|
|
{
|
|
|
|
return proto == Proxy::LazyProto;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSObject *
|
|
|
|
js::TaggedProto::toObject() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isObject());
|
|
|
|
return proto;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSObject *
|
|
|
|
js::TaggedProto::toObjectOrNull() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(!proto || isObject());
|
|
|
|
return proto;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class Outer>
|
|
|
|
inline bool
|
2012-09-24 18:08:22 -07:00
|
|
|
js::TaggedProtoOperations<Outer>::isLazy() const
|
2012-09-26 09:49:20 -07:00
|
|
|
{
|
|
|
|
return value()->isLazy();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class Outer>
|
|
|
|
inline bool
|
2012-09-24 18:08:22 -07:00
|
|
|
js::TaggedProtoOperations<Outer>::isObject() const
|
2012-09-26 09:49:20 -07:00
|
|
|
{
|
|
|
|
return value()->isObject();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class Outer>
|
|
|
|
inline JSObject *
|
2012-09-24 18:08:22 -07:00
|
|
|
js::TaggedProtoOperations<Outer>::toObject() const
|
2012-09-26 09:49:20 -07:00
|
|
|
{
|
|
|
|
return value()->toObject();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class Outer>
|
|
|
|
inline JSObject *
|
2012-09-24 18:08:22 -07:00
|
|
|
js::TaggedProtoOperations<Outer>::toObjectOrNull() const
|
2012-09-26 09:49:20 -07:00
|
|
|
{
|
|
|
|
return value()->toObjectOrNull();
|
|
|
|
}
|
|
|
|
|
2012-07-16 14:19:26 -07:00
|
|
|
namespace js {
|
|
|
|
namespace types {
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
2012-07-16 14:19:26 -07:00
|
|
|
// CompilerOutput & RecompileInfo
|
2010-10-29 08:05:55 -07:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-07-16 14:19:26 -07:00
|
|
|
inline
|
|
|
|
CompilerOutput::CompilerOutput()
|
2012-07-17 03:01:22 -07:00
|
|
|
: script(NULL),
|
2012-11-13 15:58:48 -08:00
|
|
|
kindInt(MethodJIT),
|
2012-07-16 14:19:26 -07:00
|
|
|
constructing(false),
|
|
|
|
barriers(false),
|
|
|
|
chunkIndex(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-08-14 16:30:07 -07:00
|
|
|
inline mjit::JITScript *
|
|
|
|
CompilerOutput::mjit() const
|
2012-07-16 14:19:26 -07:00
|
|
|
{
|
|
|
|
#ifdef JS_METHODJIT
|
2012-11-13 15:58:48 -08:00
|
|
|
JS_ASSERT(kind() == MethodJIT && isValid());
|
2012-08-14 16:30:07 -07:00
|
|
|
return script->getJIT(constructing, barriers);
|
|
|
|
#else
|
|
|
|
return NULL;
|
2012-07-16 14:19:26 -07:00
|
|
|
#endif
|
2012-08-14 16:30:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline ion::IonScript *
|
|
|
|
CompilerOutput::ion() const
|
|
|
|
{
|
2012-11-06 10:50:19 -08:00
|
|
|
#ifdef JS_ION
|
2012-11-13 15:58:48 -08:00
|
|
|
JS_ASSERT(kind() != MethodJIT && isValid());
|
|
|
|
switch (kind()) {
|
|
|
|
case MethodJIT: break;
|
|
|
|
case Ion: return script->ionScript();
|
|
|
|
case ParallelIon: return script->parallelIonScript();
|
|
|
|
}
|
2012-11-06 10:50:19 -08:00
|
|
|
#endif
|
2012-11-13 15:58:48 -08:00
|
|
|
JS_NOT_REACHED("Invalid kind of CompilerOutput");
|
|
|
|
return NULL;
|
2012-07-16 14:19:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
CompilerOutput::isValid() const
|
|
|
|
{
|
2012-08-14 16:30:07 -07:00
|
|
|
if (!script)
|
|
|
|
return false;
|
|
|
|
|
2012-11-06 10:50:19 -08:00
|
|
|
#if defined(DEBUG) && (defined(JS_METHODJIT) || defined(JS_ION))
|
2012-08-14 16:30:07 -07:00
|
|
|
TypeCompartment &types = script->compartment()->types;
|
|
|
|
#endif
|
|
|
|
|
2012-11-13 15:58:48 -08:00
|
|
|
switch (kind()) {
|
|
|
|
case MethodJIT: {
|
2012-07-16 14:19:26 -07:00
|
|
|
#ifdef JS_METHODJIT
|
2012-08-14 16:30:07 -07:00
|
|
|
mjit::JITScript *jit = script->getJIT(constructing, barriers);
|
|
|
|
if (!jit)
|
|
|
|
return false;
|
|
|
|
mjit::JITChunk *chunk = jit->chunkDescriptor(chunkIndex).chunk;
|
|
|
|
if (!chunk)
|
|
|
|
return false;
|
|
|
|
JS_ASSERT(this == chunk->recompileInfo.compilerOutput(types));
|
2012-07-16 14:19:26 -07:00
|
|
|
return true;
|
|
|
|
#endif
|
2012-11-13 15:58:48 -08:00
|
|
|
}
|
2012-08-14 16:30:07 -07:00
|
|
|
|
2012-11-13 15:58:48 -08:00
|
|
|
case Ion:
|
2012-11-06 10:50:19 -08:00
|
|
|
#ifdef JS_ION
|
2012-08-23 05:56:35 -07:00
|
|
|
if (script->hasIonScript()) {
|
|
|
|
JS_ASSERT(this == script->ion->recompileInfo().compilerOutput(types));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (script->isIonCompilingOffThread())
|
|
|
|
return true;
|
2012-11-13 15:58:48 -08:00
|
|
|
#endif
|
2012-08-23 05:56:35 -07:00
|
|
|
return false;
|
2012-11-13 15:58:48 -08:00
|
|
|
|
|
|
|
case ParallelIon:
|
|
|
|
#ifdef JS_ION
|
|
|
|
if (script->hasParallelIonScript()) {
|
|
|
|
JS_ASSERT(this == script->parallelIonScript()->recompileInfo().compilerOutput(types));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (script->isParallelIonCompilingOffThread())
|
|
|
|
return true;
|
2012-11-06 10:50:19 -08:00
|
|
|
#endif
|
2012-11-13 15:58:48 -08:00
|
|
|
return false;
|
|
|
|
}
|
2012-07-16 14:19:26 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-14 16:30:07 -07:00
|
|
|
inline CompilerOutput*
|
|
|
|
RecompileInfo::compilerOutput(TypeCompartment &types) const
|
|
|
|
{
|
|
|
|
return &(*types.constrainedOutputs)[outputIndex];
|
|
|
|
}
|
|
|
|
|
2012-07-16 14:19:26 -07:00
|
|
|
inline CompilerOutput*
|
|
|
|
RecompileInfo::compilerOutput(JSContext *cx) const
|
|
|
|
{
|
2012-08-14 16:30:07 -07:00
|
|
|
return compilerOutput(cx->compartment->types);
|
2012-07-16 14:19:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Types
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2011-07-15 10:14:07 -07:00
|
|
|
/* static */ inline Type
|
2012-09-16 16:32:02 -07:00
|
|
|
Type::ObjectType(RawObject obj)
|
2011-07-15 10:14:07 -07:00
|
|
|
{
|
|
|
|
if (obj->hasSingletonType())
|
2012-01-11 00:23:05 -08:00
|
|
|
return Type(uintptr_t(obj) | 1);
|
|
|
|
return Type(uintptr_t(obj->type()));
|
2011-07-15 10:14:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ inline Type
|
|
|
|
Type::ObjectType(TypeObject *obj)
|
|
|
|
{
|
|
|
|
if (obj->singleton)
|
2012-01-11 00:23:05 -08:00
|
|
|
return Type(uintptr_t(obj->singleton.get()) | 1);
|
|
|
|
return Type(uintptr_t(obj));
|
2011-07-15 10:14:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ inline Type
|
|
|
|
Type::ObjectType(TypeObjectKey *obj)
|
|
|
|
{
|
2012-01-11 00:23:05 -08:00
|
|
|
return Type(uintptr_t(obj));
|
2011-07-15 10:14:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline Type
|
2010-10-29 08:05:55 -07:00
|
|
|
GetValueType(JSContext *cx, const Value &val)
|
|
|
|
{
|
2011-03-03 14:07:48 -08:00
|
|
|
JS_ASSERT(cx->typeInferenceEnabled());
|
2010-10-29 08:05:55 -07:00
|
|
|
if (val.isDouble())
|
2011-07-15 10:14:07 -07:00
|
|
|
return Type::DoubleType();
|
|
|
|
if (val.isObject())
|
|
|
|
return Type::ObjectType(&val.toObject());
|
|
|
|
return Type::PrimitiveType(val.extractNonDoubleType());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline TypeFlags
|
|
|
|
PrimitiveTypeFlag(JSValueType type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
2010-10-29 08:05:55 -07:00
|
|
|
case JSVAL_TYPE_UNDEFINED:
|
2011-07-15 10:14:07 -07:00
|
|
|
return TYPE_FLAG_UNDEFINED;
|
|
|
|
case JSVAL_TYPE_NULL:
|
|
|
|
return TYPE_FLAG_NULL;
|
2010-10-29 08:05:55 -07:00
|
|
|
case JSVAL_TYPE_BOOLEAN:
|
2011-07-15 10:14:07 -07:00
|
|
|
return TYPE_FLAG_BOOLEAN;
|
|
|
|
case JSVAL_TYPE_INT32:
|
|
|
|
return TYPE_FLAG_INT32;
|
|
|
|
case JSVAL_TYPE_DOUBLE:
|
|
|
|
return TYPE_FLAG_DOUBLE;
|
2010-10-29 08:05:55 -07:00
|
|
|
case JSVAL_TYPE_STRING:
|
2011-07-15 10:14:07 -07:00
|
|
|
return TYPE_FLAG_STRING;
|
2011-05-26 12:28:19 -07:00
|
|
|
case JSVAL_TYPE_MAGIC:
|
2011-07-15 10:14:07 -07:00
|
|
|
return TYPE_FLAG_LAZYARGS;
|
2010-10-29 08:05:55 -07:00
|
|
|
default:
|
2011-07-15 10:14:07 -07:00
|
|
|
JS_NOT_REACHED("Bad type");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSValueType
|
|
|
|
TypeFlagPrimitive(TypeFlags flags)
|
|
|
|
{
|
|
|
|
switch (flags) {
|
|
|
|
case TYPE_FLAG_UNDEFINED:
|
|
|
|
return JSVAL_TYPE_UNDEFINED;
|
|
|
|
case TYPE_FLAG_NULL:
|
|
|
|
return JSVAL_TYPE_NULL;
|
|
|
|
case TYPE_FLAG_BOOLEAN:
|
|
|
|
return JSVAL_TYPE_BOOLEAN;
|
|
|
|
case TYPE_FLAG_INT32:
|
|
|
|
return JSVAL_TYPE_INT32;
|
|
|
|
case TYPE_FLAG_DOUBLE:
|
|
|
|
return JSVAL_TYPE_DOUBLE;
|
|
|
|
case TYPE_FLAG_STRING:
|
|
|
|
return JSVAL_TYPE_STRING;
|
|
|
|
case TYPE_FLAG_LAZYARGS:
|
|
|
|
return JSVAL_TYPE_MAGIC;
|
|
|
|
default:
|
|
|
|
JS_NOT_REACHED("Bad type");
|
|
|
|
return (JSValueType) 0;
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the canonical representation of an id to use when doing inference. This
|
|
|
|
* maintains the constraint that if two different jsids map to the same property
|
|
|
|
* in JS (e.g. 3 and "3"), they have the same type representation.
|
|
|
|
*/
|
2012-12-31 12:40:21 -08:00
|
|
|
inline RawId
|
|
|
|
IdToTypeId(RawId id)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-05-20 19:33:06 -07:00
|
|
|
JS_ASSERT(!JSID_IS_EMPTY(id));
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
/*
|
|
|
|
* All integers must map to the aggregate property for index types, including
|
|
|
|
* negative integers.
|
|
|
|
*/
|
|
|
|
if (JSID_IS_INT(id))
|
|
|
|
return JSID_VOID;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for numeric strings, as in js_StringIsIndex, but allow negative
|
2010-12-18 20:44:51 -08:00
|
|
|
* and overflowing integers.
|
2010-10-29 08:05:55 -07:00
|
|
|
*/
|
|
|
|
if (JSID_IS_STRING(id)) {
|
2010-12-20 09:06:43 -08:00
|
|
|
JSFlatString *str = JSID_TO_FLAT_STRING(id);
|
2012-11-09 09:45:25 -08:00
|
|
|
TwoByteChars cp = str->range();
|
|
|
|
if (JS7_ISDEC(cp[0]) || cp[0] == '-') {
|
|
|
|
for (size_t i = 1; i < cp.length(); ++i) {
|
|
|
|
if (!JS7_ISDEC(cp[i]))
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
return JSID_VOID;
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
2011-03-03 14:07:48 -08:00
|
|
|
return id;
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return JSID_VOID;
|
|
|
|
}
|
|
|
|
|
2010-12-19 08:09:45 -08:00
|
|
|
const char * TypeIdStringImpl(jsid id);
|
|
|
|
|
2010-11-18 15:18:23 -08:00
|
|
|
/* Convert an id for printing during debug. */
|
|
|
|
static inline const char *
|
2012-12-31 12:40:21 -08:00
|
|
|
TypeIdString(RawId id)
|
2010-11-18 15:18:23 -08:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2010-12-07 17:11:37 -08:00
|
|
|
return TypeIdStringImpl(id);
|
2010-11-18 15:18:23 -08:00
|
|
|
#else
|
2010-11-24 17:41:52 -08:00
|
|
|
return "(missing)";
|
2010-11-18 15:18:23 -08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-06-28 18:58:51 -07:00
|
|
|
/* Assert code to know which PCs are reasonable to be considering inlining on. */
|
2012-06-25 16:06:55 -07:00
|
|
|
inline bool
|
|
|
|
IsInlinableCall(jsbytecode *pc)
|
|
|
|
{
|
|
|
|
JSOp op = JSOp(*pc);
|
|
|
|
|
2013-02-21 05:56:54 -08:00
|
|
|
// CALL, FUNCALL, FUNAPPLY, EVAL (Standard callsites)
|
2012-06-28 18:58:51 -07:00
|
|
|
// NEW (IonMonkey-only callsite)
|
2012-06-25 16:06:55 -07:00
|
|
|
// GETPROP, CALLPROP, and LENGTH. (Inlined Getters)
|
|
|
|
// SETPROP, SETNAME, SETGNAME (Inlined Setters)
|
2013-02-21 05:56:54 -08:00
|
|
|
return op == JSOP_CALL || op == JSOP_FUNCALL || op == JSOP_FUNAPPLY || op == JSOP_EVAL ||
|
2012-06-28 18:58:51 -07:00
|
|
|
#ifdef JS_ION
|
|
|
|
op == JSOP_NEW ||
|
|
|
|
#endif
|
2012-06-25 16:06:55 -07:00
|
|
|
op == JSOP_GETPROP || op == JSOP_CALLPROP || op == JSOP_LENGTH ||
|
|
|
|
op == JSOP_SETPROP || op == JSOP_SETGNAME || op == JSOP_SETNAME;
|
|
|
|
}
|
|
|
|
|
2011-03-03 14:07:48 -08:00
|
|
|
/*
|
|
|
|
* Structure for type inference entry point functions. All functions which can
|
|
|
|
* change type information must use this, and functions which depend on
|
|
|
|
* intermediate types (i.e. JITs) can use this to ensure that intermediate
|
|
|
|
* information is not collected and does not change.
|
|
|
|
*
|
|
|
|
* Pins inference results so that intermediate type information, TypeObjects
|
|
|
|
* and JSScripts won't be collected during GC. Does additional sanity checking
|
|
|
|
* that inference is not reentrant and that recompilations occur properly.
|
|
|
|
*/
|
2013-01-18 08:23:28 -08:00
|
|
|
struct AutoEnterAnalysis
|
2011-03-03 14:07:48 -08:00
|
|
|
{
|
2013-01-18 08:23:28 -08:00
|
|
|
/* Prevent GC activity in the middle of analysis. */
|
|
|
|
gc::AutoSuppressGC suppressGC;
|
|
|
|
|
2012-03-20 03:22:05 -07:00
|
|
|
FreeOp *freeOp;
|
|
|
|
JSCompartment *compartment;
|
2011-04-22 07:59:45 -07:00
|
|
|
bool oldActiveAnalysis;
|
2011-03-03 14:07:48 -08:00
|
|
|
|
2013-01-18 08:23:28 -08:00
|
|
|
AutoEnterAnalysis(JSContext *cx)
|
|
|
|
: suppressGC(cx)
|
2011-03-03 14:07:48 -08:00
|
|
|
{
|
2012-03-20 03:22:05 -07:00
|
|
|
init(cx->runtime->defaultFreeOp(), cx->compartment);
|
|
|
|
}
|
|
|
|
|
2013-01-18 08:23:28 -08:00
|
|
|
AutoEnterAnalysis(FreeOp *fop, JSCompartment *comp)
|
|
|
|
: suppressGC(comp)
|
2012-03-20 03:22:05 -07:00
|
|
|
{
|
|
|
|
init(fop, comp);
|
2011-03-03 14:07:48 -08:00
|
|
|
}
|
|
|
|
|
2013-01-18 08:23:28 -08:00
|
|
|
~AutoEnterAnalysis()
|
2011-03-03 14:07:48 -08:00
|
|
|
{
|
2012-03-20 03:22:05 -07:00
|
|
|
compartment->activeAnalysis = oldActiveAnalysis;
|
2011-03-03 14:07:48 -08:00
|
|
|
|
|
|
|
/*
|
2011-04-22 07:59:45 -07:00
|
|
|
* If there are no more type inference activations on the stack,
|
|
|
|
* process any triggered recompilations. Note that we should not be
|
|
|
|
* invoking any scripted code while type inference is running.
|
|
|
|
* :TODO: assert this.
|
2011-03-03 14:07:48 -08:00
|
|
|
*/
|
2013-01-18 08:23:28 -08:00
|
|
|
if (!compartment->activeAnalysis) {
|
2012-03-20 03:22:05 -07:00
|
|
|
TypeCompartment *types = &compartment->types;
|
2013-03-16 20:36:37 -07:00
|
|
|
if (compartment->zone()->types.pendingNukeTypes)
|
|
|
|
compartment->zone()->types.nukeTypes(freeOp);
|
2011-04-22 07:59:45 -07:00
|
|
|
else if (types->pendingRecompiles)
|
2012-03-20 03:22:05 -07:00
|
|
|
types->processPendingRecompiles(freeOp);
|
2011-04-22 07:59:45 -07:00
|
|
|
}
|
2011-03-03 14:07:48 -08:00
|
|
|
}
|
2012-03-20 03:22:05 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
void init(FreeOp *fop, JSCompartment *comp) {
|
|
|
|
freeOp = fop;
|
|
|
|
compartment = comp;
|
|
|
|
oldActiveAnalysis = compartment->activeAnalysis;
|
|
|
|
compartment->activeAnalysis = true;
|
|
|
|
}
|
2011-04-22 07:59:45 -07:00
|
|
|
};
|
2011-03-03 14:07:48 -08:00
|
|
|
|
2011-03-30 14:10:16 -07:00
|
|
|
/*
|
|
|
|
* Structure marking the currently compiled script, for constraints which can
|
|
|
|
* trigger recompilation.
|
|
|
|
*/
|
|
|
|
struct AutoEnterCompilation
|
|
|
|
{
|
2012-07-16 14:19:26 -07:00
|
|
|
JSContext *cx;
|
2012-01-18 16:40:18 -08:00
|
|
|
RecompileInfo &info;
|
2012-11-13 15:58:48 -08:00
|
|
|
CompilerOutput::Kind kind;
|
2011-03-30 14:10:16 -07:00
|
|
|
|
2012-11-13 15:58:48 -08:00
|
|
|
AutoEnterCompilation(JSContext *cx, CompilerOutput::Kind kind)
|
2012-07-16 14:19:26 -07:00
|
|
|
: cx(cx),
|
|
|
|
info(cx->compartment->types.compiledInfo),
|
2012-11-13 15:58:48 -08:00
|
|
|
kind(kind)
|
2012-07-16 14:19:26 -07:00
|
|
|
{
|
2012-08-22 16:05:08 -07:00
|
|
|
JS_ASSERT(cx->compartment->activeAnalysis);
|
2012-07-16 14:19:26 -07:00
|
|
|
JS_ASSERT(info.outputIndex == RecompileInfo::NoCompilerRunning);
|
|
|
|
}
|
2011-03-30 14:10:16 -07:00
|
|
|
|
2013-03-05 10:32:12 -08:00
|
|
|
bool init(RawScript script, bool constructing, unsigned chunkIndex)
|
2011-03-30 14:10:16 -07:00
|
|
|
{
|
2012-07-16 14:19:26 -07:00
|
|
|
CompilerOutput co;
|
|
|
|
co.script = script;
|
2012-11-13 15:58:48 -08:00
|
|
|
co.setKind(kind);
|
2012-07-16 14:19:26 -07:00
|
|
|
co.constructing = constructing;
|
2013-01-27 13:51:41 -08:00
|
|
|
co.barriers = cx->zone()->compileBarriers();
|
2012-07-16 14:19:26 -07:00
|
|
|
co.chunkIndex = chunkIndex;
|
|
|
|
|
2012-08-14 16:30:07 -07:00
|
|
|
// This flag is used to prevent adding the current compiled script in
|
|
|
|
// the list of compiler output which should be invalided. This is
|
|
|
|
// necessary because we can run some analysis might discard the script
|
|
|
|
// it-self, which can happen when the monitored value does not reflect
|
|
|
|
// the types propagated by the type inference.
|
|
|
|
co.pendingRecompilation = true;
|
|
|
|
|
|
|
|
JS_ASSERT(!co.isValid());
|
2012-07-16 14:19:26 -07:00
|
|
|
TypeCompartment &types = cx->compartment->types;
|
|
|
|
if (!types.constrainedOutputs) {
|
|
|
|
types.constrainedOutputs = cx->new_< Vector<CompilerOutput> >(cx);
|
|
|
|
if (!types.constrainedOutputs) {
|
|
|
|
types.setPendingNukeTypes(cx);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-27 07:12:09 -08:00
|
|
|
info.outputIndex = types.constrainedOutputs->length();
|
2012-07-16 14:19:26 -07:00
|
|
|
// I hope we GC before we reach 64k of compilation attempts.
|
|
|
|
if (info.outputIndex >= RecompileInfo::NoCompilerRunning)
|
|
|
|
return false;
|
|
|
|
|
2012-12-27 07:12:09 -08:00
|
|
|
if (!types.constrainedOutputs->append(co)) {
|
|
|
|
info.outputIndex = RecompileInfo::NoCompilerRunning;
|
2012-07-16 14:19:26 -07:00
|
|
|
return false;
|
2012-12-27 07:12:09 -08:00
|
|
|
}
|
2012-07-16 14:19:26 -07:00
|
|
|
return true;
|
2011-03-30 14:10:16 -07:00
|
|
|
}
|
|
|
|
|
2012-08-23 05:56:35 -07:00
|
|
|
void initExisting(RecompileInfo oldInfo)
|
|
|
|
{
|
|
|
|
// Initialize the active compilation index from that produced during a
|
|
|
|
// previous compilation, for finishing an off thread compilation.
|
|
|
|
info = oldInfo;
|
|
|
|
}
|
|
|
|
|
2011-03-30 14:10:16 -07:00
|
|
|
~AutoEnterCompilation()
|
|
|
|
{
|
2012-12-27 07:12:09 -08:00
|
|
|
// Handle failure cases of init.
|
|
|
|
if (info.outputIndex >= RecompileInfo::NoCompilerRunning)
|
|
|
|
return;
|
|
|
|
|
|
|
|
JS_ASSERT(info.outputIndex < cx->compartment->types.constrainedOutputs->length());
|
2012-07-16 14:19:26 -07:00
|
|
|
CompilerOutput *co = info.compilerOutput(cx);
|
2012-08-14 16:30:07 -07:00
|
|
|
co->pendingRecompilation = false;
|
|
|
|
if (!co->isValid())
|
|
|
|
co->invalidate();
|
|
|
|
|
2012-07-16 14:19:26 -07:00
|
|
|
info.outputIndex = RecompileInfo::NoCompilerRunning;
|
2011-03-30 14:10:16 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
2011-06-02 10:40:27 -07:00
|
|
|
// Interface functions
|
2010-10-29 08:05:55 -07:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-06-02 10:40:27 -07:00
|
|
|
/*
|
|
|
|
* These functions check whether inference is enabled before performing some
|
|
|
|
* action on the type state. To avoid checking cx->typeInferenceEnabled()
|
|
|
|
* everywhere, it is generally preferred to use one of these functions or
|
|
|
|
* a type function on JSScript to perform inference operations.
|
|
|
|
*/
|
2011-03-03 14:07:48 -08:00
|
|
|
|
2013-01-23 11:57:55 -08:00
|
|
|
inline Class *
|
|
|
|
GetClassForProtoKey(JSProtoKey key)
|
|
|
|
{
|
|
|
|
switch (key) {
|
|
|
|
case JSProto_Object:
|
|
|
|
return &ObjectClass;
|
|
|
|
case JSProto_Array:
|
|
|
|
return &ArrayClass;
|
|
|
|
|
|
|
|
case JSProto_Number:
|
|
|
|
return &NumberClass;
|
|
|
|
case JSProto_Boolean:
|
|
|
|
return &BooleanClass;
|
|
|
|
case JSProto_String:
|
|
|
|
return &StringClass;
|
|
|
|
case JSProto_RegExp:
|
|
|
|
return &RegExpClass;
|
|
|
|
|
|
|
|
case JSProto_Int8Array:
|
|
|
|
case JSProto_Uint8Array:
|
|
|
|
case JSProto_Int16Array:
|
|
|
|
case JSProto_Uint16Array:
|
|
|
|
case JSProto_Int32Array:
|
|
|
|
case JSProto_Uint32Array:
|
|
|
|
case JSProto_Float32Array:
|
|
|
|
case JSProto_Float64Array:
|
|
|
|
case JSProto_Uint8ClampedArray:
|
|
|
|
return &TypedArray::classes[key - JSProto_Int8Array];
|
|
|
|
|
|
|
|
case JSProto_ArrayBuffer:
|
|
|
|
return &ArrayBufferClass;
|
|
|
|
|
|
|
|
case JSProto_DataView:
|
|
|
|
return &DataViewClass;
|
|
|
|
|
|
|
|
default:
|
|
|
|
JS_NOT_REACHED("Bad proto key");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-02 10:40:27 -07:00
|
|
|
/*
|
|
|
|
* Get the default 'new' object for a given standard class, per the currently
|
|
|
|
* active global.
|
|
|
|
*/
|
|
|
|
inline TypeObject *
|
|
|
|
GetTypeNewObject(JSContext *cx, JSProtoKey key)
|
2010-11-24 17:41:52 -08:00
|
|
|
{
|
2013-03-06 08:41:42 -08:00
|
|
|
RootedObject proto(cx);
|
2012-08-17 11:21:57 -07:00
|
|
|
if (!js_GetClassPrototype(cx, key, &proto))
|
2010-12-18 20:44:51 -08:00
|
|
|
return NULL;
|
2013-01-23 11:57:55 -08:00
|
|
|
return proto->getNewType(cx, GetClassForProtoKey(key));
|
2010-11-24 17:41:52 -08:00
|
|
|
}
|
|
|
|
|
2011-06-02 10:40:27 -07:00
|
|
|
/* Get a type object for the immediate allocation site within a native. */
|
|
|
|
inline TypeObject *
|
2011-06-15 11:26:12 -07:00
|
|
|
GetTypeCallerInitObject(JSContext *cx, JSProtoKey key)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-06-02 10:40:27 -07:00
|
|
|
if (cx->typeInferenceEnabled()) {
|
2011-06-05 22:39:45 -07:00
|
|
|
jsbytecode *pc;
|
2012-09-16 16:32:06 -07:00
|
|
|
RootedScript script(cx, cx->stack.currentScript(&pc));
|
2011-08-01 22:24:29 -07:00
|
|
|
if (script)
|
2011-07-28 09:16:53 -07:00
|
|
|
return TypeScript::InitObject(cx, script, pc, key);
|
2011-03-03 14:07:48 -08:00
|
|
|
}
|
2011-06-15 11:26:12 -07:00
|
|
|
return GetTypeNewObject(cx, key);
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2012-11-16 13:59:26 -08:00
|
|
|
void MarkIteratorUnknownSlow(JSContext *cx);
|
|
|
|
|
2011-06-10 19:03:57 -07:00
|
|
|
/*
|
|
|
|
* When using a custom iterator within the initialization of a 'for in' loop,
|
|
|
|
* mark the iterator values as unknown.
|
|
|
|
*/
|
2011-05-09 07:12:47 -07:00
|
|
|
inline void
|
2011-06-10 19:03:57 -07:00
|
|
|
MarkIteratorUnknown(JSContext *cx)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-06-02 10:40:27 -07:00
|
|
|
if (cx->typeInferenceEnabled())
|
2011-06-10 19:03:57 -07:00
|
|
|
MarkIteratorUnknownSlow(cx);
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2013-01-26 06:42:20 -08:00
|
|
|
void TypeMonitorCallSlow(JSContext *cx, JSObject *callee, const CallArgs &args,
|
2012-11-16 13:59:26 -08:00
|
|
|
bool constructing);
|
|
|
|
|
2011-06-02 10:40:27 -07:00
|
|
|
/*
|
2011-10-27 08:11:26 -07:00
|
|
|
* Monitor a javascript call, either on entry to the interpreter or made
|
|
|
|
* from within the interpreter.
|
2011-06-02 10:40:27 -07:00
|
|
|
*/
|
2012-04-10 12:24:46 -07:00
|
|
|
inline bool
|
2011-10-27 08:11:26 -07:00
|
|
|
TypeMonitorCall(JSContext *cx, const js::CallArgs &args, bool constructing)
|
2011-06-02 10:40:27 -07:00
|
|
|
{
|
2013-01-26 06:42:20 -08:00
|
|
|
if (args.callee().isFunction()) {
|
|
|
|
JSFunction *fun = args.callee().toFunction();
|
2011-09-01 12:20:30 -07:00
|
|
|
if (fun->isInterpreted()) {
|
2013-01-26 06:42:20 -08:00
|
|
|
if (!fun->nonLazyScript()->ensureRanAnalysis(cx))
|
2012-04-10 12:24:46 -07:00
|
|
|
return false;
|
2011-09-01 12:20:30 -07:00
|
|
|
if (cx->typeInferenceEnabled())
|
2013-01-26 06:42:20 -08:00
|
|
|
TypeMonitorCallSlow(cx, &args.callee(), args, constructing);
|
2011-09-01 12:20:30 -07:00
|
|
|
}
|
2011-03-03 14:07:48 -08:00
|
|
|
}
|
2012-04-10 12:24:46 -07:00
|
|
|
|
|
|
|
return true;
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2011-07-15 10:14:07 -07:00
|
|
|
inline bool
|
2013-03-05 10:32:12 -08:00
|
|
|
TrackPropertyTypes(JSContext *cx, RawObject obj, RawId id)
|
2011-07-15 10:14:07 -07:00
|
|
|
{
|
2011-07-21 07:28:01 -07:00
|
|
|
if (!cx->typeInferenceEnabled() || obj->hasLazyType() || obj->type()->unknownProperties())
|
|
|
|
return false;
|
|
|
|
|
2012-12-31 12:40:21 -08:00
|
|
|
if (obj->hasSingletonType() && !obj->type()->maybeGetProperty(id, cx))
|
2011-07-21 07:28:01 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2011-07-15 10:14:07 -07:00
|
|
|
}
|
|
|
|
|
2011-06-02 10:40:27 -07:00
|
|
|
/* Add a possible type for a property of obj. */
|
2011-05-09 07:12:47 -07:00
|
|
|
inline void
|
2013-01-24 19:18:34 -08:00
|
|
|
AddTypePropertyId(JSContext *cx, JSObject *obj, jsid id, Type type)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-07-21 07:28:01 -07:00
|
|
|
if (cx->typeInferenceEnabled())
|
2012-12-31 12:40:21 -08:00
|
|
|
id = IdToTypeId(id);
|
2011-07-15 10:14:07 -07:00
|
|
|
if (TrackPropertyTypes(cx, obj, id))
|
|
|
|
obj->type()->addPropertyType(cx, id, type);
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2011-05-09 07:12:47 -07:00
|
|
|
inline void
|
2013-01-24 19:18:34 -08:00
|
|
|
AddTypePropertyId(JSContext *cx, JSObject *obj, jsid id, const Value &value)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-07-21 07:28:01 -07:00
|
|
|
if (cx->typeInferenceEnabled())
|
2012-12-31 12:40:21 -08:00
|
|
|
id = IdToTypeId(id);
|
2011-07-15 10:14:07 -07:00
|
|
|
if (TrackPropertyTypes(cx, obj, id))
|
|
|
|
obj->type()->addPropertyType(cx, id, value);
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2011-05-09 07:12:47 -07:00
|
|
|
inline void
|
2011-07-15 10:14:07 -07:00
|
|
|
AddTypeProperty(JSContext *cx, TypeObject *obj, const char *name, Type type)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-06-02 10:40:27 -07:00
|
|
|
if (cx->typeInferenceEnabled() && !obj->unknownProperties())
|
|
|
|
obj->addPropertyType(cx, name, type);
|
2010-12-21 18:26:09 -08:00
|
|
|
}
|
|
|
|
|
2011-05-09 07:12:47 -07:00
|
|
|
inline void
|
2011-06-02 10:40:27 -07:00
|
|
|
AddTypeProperty(JSContext *cx, TypeObject *obj, const char *name, const Value &value)
|
2011-03-15 23:50:44 -07:00
|
|
|
{
|
2011-06-02 10:40:27 -07:00
|
|
|
if (cx->typeInferenceEnabled() && !obj->unknownProperties())
|
|
|
|
obj->addPropertyType(cx, name, value);
|
2011-03-15 23:50:44 -07:00
|
|
|
}
|
|
|
|
|
2011-06-02 10:40:27 -07:00
|
|
|
/* Set one or more dynamic flags on a type object. */
|
2011-05-09 07:12:47 -07:00
|
|
|
inline void
|
2012-09-16 16:32:02 -07:00
|
|
|
MarkTypeObjectFlags(JSContext *cx, RawObject obj, TypeObjectFlags flags)
|
2011-04-11 20:10:46 -07:00
|
|
|
{
|
2011-07-25 07:13:02 -07:00
|
|
|
if (cx->typeInferenceEnabled() && !obj->hasLazyType() && !obj->type()->hasAllFlags(flags))
|
|
|
|
obj->type()->setFlags(cx, flags);
|
2011-04-11 20:10:46 -07:00
|
|
|
}
|
|
|
|
|
2011-07-15 10:14:07 -07:00
|
|
|
/*
|
|
|
|
* Mark all properties of a type object as unknown. If markSetsUnknown is set,
|
|
|
|
* scan the entire compartment and mark all type sets containing it as having
|
|
|
|
* an unknown object. This is needed for correctness in dealing with mutable
|
|
|
|
* __proto__, which can change the type of an object dynamically.
|
|
|
|
*/
|
2011-05-09 07:12:47 -07:00
|
|
|
inline void
|
2011-07-15 10:14:07 -07:00
|
|
|
MarkTypeObjectUnknownProperties(JSContext *cx, TypeObject *obj,
|
|
|
|
bool markSetsUnknown = false)
|
2011-04-11 20:10:46 -07:00
|
|
|
{
|
2011-07-15 10:14:07 -07:00
|
|
|
if (cx->typeInferenceEnabled()) {
|
|
|
|
if (!obj->unknownProperties())
|
|
|
|
obj->markUnknown(cx);
|
2011-07-21 07:28:01 -07:00
|
|
|
if (markSetsUnknown && !(obj->flags & OBJECT_FLAG_SETS_MARKED_UNKNOWN))
|
2011-07-15 10:14:07 -07:00
|
|
|
cx->compartment->types.markSetsUnknown(cx, obj);
|
|
|
|
}
|
2011-04-11 20:10:46 -07:00
|
|
|
}
|
|
|
|
|
2011-06-02 10:40:27 -07:00
|
|
|
/*
|
|
|
|
* Mark any property which has been deleted or configured to be non-writable or
|
|
|
|
* have a getter/setter.
|
|
|
|
*/
|
2011-05-09 07:12:47 -07:00
|
|
|
inline void
|
2012-12-31 12:40:21 -08:00
|
|
|
MarkTypePropertyConfigured(JSContext *cx, HandleObject obj, RawId id)
|
2010-11-09 14:40:10 -08:00
|
|
|
{
|
2011-07-21 07:28:01 -07:00
|
|
|
if (cx->typeInferenceEnabled())
|
2012-12-31 12:40:21 -08:00
|
|
|
id = IdToTypeId(id);
|
2011-07-21 07:28:01 -07:00
|
|
|
if (TrackPropertyTypes(cx, obj, id))
|
2011-07-15 10:14:07 -07:00
|
|
|
obj->type()->markPropertyConfigured(cx, id);
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2011-08-09 09:52:55 -07:00
|
|
|
/* Mark a state change on a particular object. */
|
2011-05-09 07:12:47 -07:00
|
|
|
inline void
|
2012-11-29 10:22:10 -08:00
|
|
|
MarkObjectStateChange(JSContext *cx, RawObject obj)
|
2010-11-24 17:41:52 -08:00
|
|
|
{
|
2011-08-09 09:52:55 -07:00
|
|
|
if (cx->typeInferenceEnabled() && !obj->hasLazyType() && !obj->type()->unknownProperties())
|
|
|
|
obj->type()->markStateChange(cx);
|
2010-11-24 17:41:52 -08:00
|
|
|
}
|
|
|
|
|
2011-06-02 10:40:27 -07:00
|
|
|
/*
|
|
|
|
* For an array or object which has not yet escaped and been referenced elsewhere,
|
|
|
|
* pick a new type based on the object's current contents.
|
|
|
|
*/
|
|
|
|
|
2011-05-09 07:12:47 -07:00
|
|
|
inline void
|
2012-09-16 16:32:02 -07:00
|
|
|
FixArrayType(JSContext *cx, HandleObject obj)
|
2011-03-10 16:17:39 -08:00
|
|
|
{
|
2011-06-02 10:40:27 -07:00
|
|
|
if (cx->typeInferenceEnabled())
|
|
|
|
cx->compartment->types.fixArrayType(cx, obj);
|
2011-03-10 16:17:39 -08:00
|
|
|
}
|
|
|
|
|
2011-05-09 07:12:47 -07:00
|
|
|
inline void
|
2012-09-16 16:32:02 -07:00
|
|
|
FixObjectType(JSContext *cx, HandleObject obj)
|
2011-03-10 16:17:39 -08:00
|
|
|
{
|
2011-06-02 10:40:27 -07:00
|
|
|
if (cx->typeInferenceEnabled())
|
|
|
|
cx->compartment->types.fixObjectType(cx, obj);
|
2011-03-10 16:17:39 -08:00
|
|
|
}
|
|
|
|
|
2012-11-29 10:22:12 -08:00
|
|
|
/* Interface helpers for RawScript */
|
2013-01-26 06:42:20 -08:00
|
|
|
extern void TypeMonitorResult(JSContext *cx, JSScript *script, jsbytecode *pc,
|
2012-09-16 16:32:06 -07:00
|
|
|
const js::Value &rval);
|
2013-01-26 06:42:20 -08:00
|
|
|
extern void TypeDynamicResult(JSContext *cx, JSScript *script, jsbytecode *pc,
|
2012-09-16 16:32:06 -07:00
|
|
|
js::types::Type type);
|
2011-06-02 10:40:27 -07:00
|
|
|
|
2011-07-07 21:02:57 -07:00
|
|
|
inline bool
|
|
|
|
UseNewTypeAtEntry(JSContext *cx, StackFrame *fp)
|
|
|
|
{
|
2012-09-16 16:32:06 -07:00
|
|
|
if (!fp->isConstructing() || !cx->typeInferenceEnabled() || !fp->prev())
|
|
|
|
return false;
|
|
|
|
|
2013-01-18 05:48:13 -08:00
|
|
|
JSScript *prevScript = fp->prev()->script();
|
2012-09-16 16:32:06 -07:00
|
|
|
return UseNewType(cx, prevScript, fp->prevpc());
|
2011-07-07 21:02:57 -07:00
|
|
|
}
|
|
|
|
|
2012-07-18 05:35:00 -07:00
|
|
|
inline bool
|
|
|
|
UseNewTypeForClone(JSFunction *fun)
|
|
|
|
{
|
2013-02-19 07:49:33 -08:00
|
|
|
if (!fun->isInterpreted())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (fun->nonLazyScript()->shouldCloneAtCallsite)
|
|
|
|
return true;
|
|
|
|
|
2013-03-18 15:32:29 -07:00
|
|
|
if (fun->isArrow())
|
|
|
|
return true;
|
|
|
|
|
2013-02-19 07:49:33 -08:00
|
|
|
if (fun->hasSingletonType())
|
2012-07-18 05:35:00 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When a function is being used as a wrapper for another function, it
|
|
|
|
* improves precision greatly to distinguish between different instances of
|
|
|
|
* the wrapper; otherwise we will conflate much of the information about
|
|
|
|
* the wrapped functions.
|
|
|
|
*
|
|
|
|
* An important example is the Class.create function at the core of the
|
|
|
|
* Prototype.js library, which looks like:
|
|
|
|
*
|
|
|
|
* var Class = {
|
|
|
|
* create: function() {
|
|
|
|
* return function() {
|
|
|
|
* this.initialize.apply(this, arguments);
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* };
|
|
|
|
*
|
|
|
|
* Each instance of the innermost function will have a different wrapped
|
|
|
|
* initialize method. We capture this, along with similar cases, by looking
|
|
|
|
* for short scripts which use both .apply and arguments. For such scripts,
|
|
|
|
* whenever creating a new instance of the function we both give that
|
|
|
|
* instance a singleton type and clone the underlying script.
|
|
|
|
*/
|
|
|
|
|
2013-03-05 10:32:12 -08:00
|
|
|
RawScript script = fun->nonLazyScript();
|
2012-07-18 05:35:00 -07:00
|
|
|
|
|
|
|
if (script->length >= 50)
|
|
|
|
return false;
|
|
|
|
|
2012-08-06 07:56:45 -07:00
|
|
|
if (script->hasConsts() || script->hasObjects() || script->hasRegexps() || fun->isHeavyweight())
|
2012-07-18 05:35:00 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
bool hasArguments = false;
|
|
|
|
bool hasApply = false;
|
|
|
|
|
|
|
|
for (jsbytecode *pc = script->code;
|
|
|
|
pc != script->code + script->length;
|
|
|
|
pc += GetBytecodeLength(pc))
|
|
|
|
{
|
|
|
|
if (*pc == JSOP_ARGUMENTS)
|
|
|
|
hasArguments = true;
|
|
|
|
if (*pc == JSOP_FUNAPPLY)
|
|
|
|
hasApply = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hasArguments && hasApply;
|
|
|
|
}
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
2011-06-02 10:40:27 -07:00
|
|
|
// Script interface functions
|
2010-10-29 08:05:55 -07:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline unsigned
|
2013-03-05 10:32:12 -08:00
|
|
|
TypeScript::NumTypeSets(RawScript script)
|
2011-06-06 08:32:41 -07:00
|
|
|
{
|
2011-08-17 06:48:14 -07:00
|
|
|
return script->nTypeSets + analyze::TotalSlots(script);
|
2011-03-01 13:10:05 -08:00
|
|
|
}
|
|
|
|
|
2012-08-22 11:28:34 -07:00
|
|
|
/* static */ inline HeapTypeSet *
|
2012-09-16 16:32:06 -07:00
|
|
|
TypeScript::ReturnTypes(RawScript script)
|
2011-03-01 13:10:05 -08:00
|
|
|
{
|
2012-08-22 11:28:34 -07:00
|
|
|
TypeSet *types = script->types->typeArray() + script->nTypeSets + js::analyze::CalleeSlot();
|
|
|
|
return types->toHeapTypeSet();
|
2011-03-01 13:10:05 -08:00
|
|
|
}
|
|
|
|
|
2012-08-22 11:28:34 -07:00
|
|
|
/* static */ inline StackTypeSet *
|
2012-09-16 16:32:06 -07:00
|
|
|
TypeScript::ThisTypes(RawScript script)
|
2011-03-01 13:10:05 -08:00
|
|
|
{
|
2012-08-22 11:28:34 -07:00
|
|
|
TypeSet *types = script->types->typeArray() + script->nTypeSets + js::analyze::ThisSlot();
|
|
|
|
return types->toStackTypeSet();
|
2011-03-01 13:10:05 -08:00
|
|
|
}
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
/*
|
|
|
|
* Note: for non-escaping arguments and locals, argTypes/localTypes reflect
|
|
|
|
* only the initial type of the variable (e.g. passed values for argTypes,
|
|
|
|
* or undefined for localTypes) and not types from subsequent assignments.
|
|
|
|
*/
|
|
|
|
|
2012-08-22 11:28:34 -07:00
|
|
|
/* static */ inline StackTypeSet *
|
2012-09-16 16:32:06 -07:00
|
|
|
TypeScript::ArgTypes(RawScript script, unsigned i)
|
2011-03-01 13:10:05 -08:00
|
|
|
{
|
2011-07-28 09:16:53 -07:00
|
|
|
JS_ASSERT(i < script->function()->nargs);
|
2012-08-22 11:28:34 -07:00
|
|
|
TypeSet *types = script->types->typeArray() + script->nTypeSets + js::analyze::ArgSlot(i);
|
|
|
|
return types->toStackTypeSet();
|
2011-04-22 07:59:45 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 11:28:34 -07:00
|
|
|
/* static */ inline StackTypeSet *
|
2012-09-16 16:32:06 -07:00
|
|
|
TypeScript::LocalTypes(RawScript script, unsigned i)
|
2011-04-22 07:59:45 -07:00
|
|
|
{
|
2011-07-28 09:16:53 -07:00
|
|
|
JS_ASSERT(i < script->nfixed);
|
2012-08-22 11:28:34 -07:00
|
|
|
TypeSet *types = script->types->typeArray() + script->nTypeSets + js::analyze::LocalSlot(script, i);
|
|
|
|
return types->toStackTypeSet();
|
2011-03-01 13:10:05 -08:00
|
|
|
}
|
|
|
|
|
2012-08-22 11:28:34 -07:00
|
|
|
/* static */ inline StackTypeSet *
|
2012-09-16 16:32:06 -07:00
|
|
|
TypeScript::SlotTypes(RawScript script, unsigned slot)
|
2010-12-28 11:53:50 -08:00
|
|
|
{
|
2011-07-28 09:16:53 -07:00
|
|
|
JS_ASSERT(slot < js::analyze::TotalSlots(script));
|
2012-08-22 11:28:34 -07:00
|
|
|
TypeSet *types = script->types->typeArray() + script->nTypeSets + slot;
|
|
|
|
return types->toStackTypeSet();
|
2010-12-28 11:53:50 -08:00
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline TypeObject *
|
2013-01-26 06:42:20 -08:00
|
|
|
TypeScript::StandardType(JSContext *cx, JSProtoKey key)
|
2010-12-28 11:53:50 -08:00
|
|
|
{
|
2013-03-06 08:41:42 -08:00
|
|
|
RootedObject proto(cx);
|
2012-08-17 11:21:57 -07:00
|
|
|
if (!js_GetClassPrototype(cx, key, &proto, NULL))
|
2010-12-28 11:53:50 -08:00
|
|
|
return NULL;
|
2013-01-23 11:57:55 -08:00
|
|
|
return proto->getNewType(cx, GetClassForProtoKey(key));
|
2010-12-28 11:53:50 -08:00
|
|
|
}
|
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
struct AllocationSiteKey {
|
|
|
|
JSScript *script;
|
2011-09-01 12:20:30 -07:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t offset : 24;
|
2011-07-21 07:28:01 -07:00
|
|
|
JSProtoKey kind : 8;
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
static const uint32_t OFFSET_LIMIT = (1 << 23);
|
2011-07-21 07:28:01 -07:00
|
|
|
|
|
|
|
AllocationSiteKey() { PodZero(this); }
|
|
|
|
|
|
|
|
typedef AllocationSiteKey Lookup;
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
static inline uint32_t hash(AllocationSiteKey key) {
|
|
|
|
return uint32_t(size_t(key.script->code + key.offset)) ^ key.kind;
|
2011-07-21 07:28:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool match(const AllocationSiteKey &a, const AllocationSiteKey &b) {
|
|
|
|
return a.script == b.script && a.offset == b.offset && a.kind == b.kind;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-28 11:01:54 -08:00
|
|
|
/* Whether to use a new type object for an initializer opcode at script/pc. */
|
|
|
|
js::NewObjectKind
|
|
|
|
UseNewTypeForInitializer(JSContext *cx, JSScript *script, jsbytecode *pc, JSProtoKey key);
|
|
|
|
|
|
|
|
js::NewObjectKind
|
|
|
|
UseNewTypeForInitializer(JSContext *cx, JSScript *script, jsbytecode *pc, Class *clasp);
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline TypeObject *
|
2013-01-26 06:42:20 -08:00
|
|
|
TypeScript::InitObject(JSContext *cx, JSScript *script, jsbytecode *pc, JSProtoKey kind)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2012-06-27 07:10:50 -07:00
|
|
|
JS_ASSERT(!UseNewTypeForInitializer(cx, script, pc, kind));
|
2012-03-21 06:37:43 -07:00
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
/* :XXX: Limit script->length so we don't need to check the offset up front? */
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t offset = pc - script->code;
|
2010-12-28 11:53:50 -08:00
|
|
|
|
2012-08-27 09:13:44 -07:00
|
|
|
if (!cx->typeInferenceEnabled() || !script->compileAndGo || offset >= AllocationSiteKey::OFFSET_LIMIT)
|
2011-07-21 07:28:01 -07:00
|
|
|
return GetTypeNewObject(cx, kind);
|
|
|
|
|
|
|
|
AllocationSiteKey key;
|
2011-07-28 09:16:53 -07:00
|
|
|
key.script = script;
|
2011-07-21 07:28:01 -07:00
|
|
|
key.offset = offset;
|
|
|
|
key.kind = kind;
|
|
|
|
|
|
|
|
if (!cx->compartment->types.allocationSiteTable)
|
2012-08-16 06:14:51 -07:00
|
|
|
return cx->compartment->types.addAllocationSiteTypeObject(cx, key);
|
2011-07-21 07:28:01 -07:00
|
|
|
|
|
|
|
AllocationSiteTable::Ptr p = cx->compartment->types.allocationSiteTable->lookup(key);
|
|
|
|
|
|
|
|
if (p)
|
|
|
|
return p->value;
|
2012-08-16 06:14:51 -07:00
|
|
|
return cx->compartment->types.addAllocationSiteTypeObject(cx, key);
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2012-03-21 06:37:43 -07:00
|
|
|
/* Set the type to use for obj according to the site it was allocated at. */
|
|
|
|
static inline bool
|
2013-01-28 11:01:54 -08:00
|
|
|
SetInitializerObjectType(JSContext *cx, HandleScript script, jsbytecode *pc, HandleObject obj, NewObjectKind kind)
|
2012-03-21 06:37:43 -07:00
|
|
|
{
|
|
|
|
if (!cx->typeInferenceEnabled())
|
|
|
|
return true;
|
|
|
|
|
2012-06-27 07:10:50 -07:00
|
|
|
JSProtoKey key = JSCLASS_CACHED_PROTO_KEY(obj->getClass());
|
|
|
|
JS_ASSERT(key != JSProto_Null);
|
2013-01-28 11:01:54 -08:00
|
|
|
JS_ASSERT(kind == UseNewTypeForInitializer(cx, script, pc, key));
|
2012-06-27 07:10:50 -07:00
|
|
|
|
2013-01-28 11:01:54 -08:00
|
|
|
if (kind == SingletonObject) {
|
|
|
|
JS_ASSERT(obj->hasSingletonType());
|
2012-03-21 06:37:43 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Inference does not account for types of run-once initializer
|
|
|
|
* objects, as these may not be created until after the script
|
|
|
|
* has been analyzed.
|
|
|
|
*/
|
|
|
|
TypeScript::Monitor(cx, script, pc, ObjectValue(*obj));
|
|
|
|
} else {
|
|
|
|
types::TypeObject *type = TypeScript::InitObject(cx, script, pc, key);
|
|
|
|
if (!type)
|
|
|
|
return false;
|
|
|
|
obj->setType(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline void
|
2013-01-26 06:42:20 -08:00
|
|
|
TypeScript::Monitor(JSContext *cx, JSScript *script, jsbytecode *pc, const js::Value &rval)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-06-02 10:40:27 -07:00
|
|
|
if (cx->typeInferenceEnabled())
|
2011-07-28 09:16:53 -07:00
|
|
|
TypeMonitorResult(cx, script, pc, rval);
|
2011-03-01 13:10:05 -08:00
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline void
|
2013-01-26 06:42:20 -08:00
|
|
|
TypeScript::MonitorOverflow(JSContext *cx, JSScript *script, jsbytecode *pc)
|
2010-11-15 18:13:05 -08:00
|
|
|
{
|
2011-05-14 05:45:13 -07:00
|
|
|
if (cx->typeInferenceEnabled())
|
2011-07-28 09:16:53 -07:00
|
|
|
TypeDynamicResult(cx, script, pc, Type::DoubleType());
|
2010-11-15 18:13:05 -08:00
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline void
|
2013-01-26 06:42:20 -08:00
|
|
|
TypeScript::MonitorString(JSContext *cx, JSScript *script, jsbytecode *pc)
|
2011-03-17 21:34:36 -07:00
|
|
|
{
|
2011-05-14 05:45:13 -07:00
|
|
|
if (cx->typeInferenceEnabled())
|
2011-07-28 09:16:53 -07:00
|
|
|
TypeDynamicResult(cx, script, pc, Type::StringType());
|
2011-03-17 21:34:36 -07:00
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline void
|
2013-01-26 06:42:20 -08:00
|
|
|
TypeScript::MonitorUnknown(JSContext *cx, JSScript *script, jsbytecode *pc)
|
2010-11-15 18:13:05 -08:00
|
|
|
{
|
2011-05-14 05:45:13 -07:00
|
|
|
if (cx->typeInferenceEnabled())
|
2011-07-28 09:16:53 -07:00
|
|
|
TypeDynamicResult(cx, script, pc, Type::UnknownType());
|
2010-11-15 18:13:05 -08:00
|
|
|
}
|
|
|
|
|
2012-01-12 10:28:03 -08:00
|
|
|
/* static */ inline void
|
2013-01-18 05:48:13 -08:00
|
|
|
TypeScript::GetPcScript(JSContext *cx, JSScript **script, jsbytecode **pc)
|
2012-01-12 10:28:03 -08:00
|
|
|
{
|
2012-02-03 16:08:11 -08:00
|
|
|
#ifdef JS_ION
|
2012-08-14 16:28:05 -07:00
|
|
|
if (cx->fp()->beginsIonActivation()) {
|
2012-01-12 10:28:03 -08:00
|
|
|
ion::GetPcScript(cx, script, pc);
|
2012-02-03 16:08:11 -08:00
|
|
|
return;
|
2012-01-12 10:28:03 -08:00
|
|
|
}
|
2012-02-03 16:08:11 -08:00
|
|
|
#endif
|
2013-01-18 05:48:13 -08:00
|
|
|
*script = cx->fp()->script();
|
2012-02-03 16:08:11 -08:00
|
|
|
*pc = cx->regs().pc;
|
2012-01-12 10:28:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ inline void
|
|
|
|
TypeScript::MonitorOverflow(JSContext *cx)
|
|
|
|
{
|
2012-09-16 16:32:06 -07:00
|
|
|
RootedScript script(cx);
|
2012-01-12 10:28:03 -08:00
|
|
|
jsbytecode *pc;
|
2013-01-18 05:48:13 -08:00
|
|
|
GetPcScript(cx, script.address(), &pc);
|
2012-01-12 10:28:03 -08:00
|
|
|
MonitorOverflow(cx, script, pc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ inline void
|
|
|
|
TypeScript::MonitorString(JSContext *cx)
|
|
|
|
{
|
2012-09-16 16:32:06 -07:00
|
|
|
RootedScript script(cx);
|
2012-01-12 10:28:03 -08:00
|
|
|
jsbytecode *pc;
|
2013-01-18 05:48:13 -08:00
|
|
|
GetPcScript(cx, script.address(), &pc);
|
2012-01-12 10:28:03 -08:00
|
|
|
MonitorString(cx, script, pc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ inline void
|
|
|
|
TypeScript::MonitorUnknown(JSContext *cx)
|
|
|
|
{
|
2012-09-16 16:32:06 -07:00
|
|
|
RootedScript script(cx);
|
2012-01-12 10:28:03 -08:00
|
|
|
jsbytecode *pc;
|
2013-01-18 05:48:13 -08:00
|
|
|
GetPcScript(cx, script.address(), &pc);
|
2012-01-12 10:28:03 -08:00
|
|
|
MonitorUnknown(cx, script, pc);
|
|
|
|
}
|
|
|
|
|
2012-01-24 07:20:34 -08:00
|
|
|
/* static */ inline void
|
|
|
|
TypeScript::Monitor(JSContext *cx, const js::Value &rval)
|
|
|
|
{
|
2012-09-16 16:32:06 -07:00
|
|
|
RootedScript script(cx);
|
2012-01-24 07:20:34 -08:00
|
|
|
jsbytecode *pc;
|
2013-01-18 05:48:13 -08:00
|
|
|
GetPcScript(cx, script.address(), &pc);
|
2012-01-24 07:20:34 -08:00
|
|
|
Monitor(cx, script, pc, rval);
|
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline void
|
2012-09-16 16:32:02 -07:00
|
|
|
TypeScript::MonitorAssign(JSContext *cx, HandleObject obj, jsid id)
|
2011-05-16 16:15:37 -07:00
|
|
|
{
|
2011-08-01 22:24:29 -07:00
|
|
|
if (cx->typeInferenceEnabled() && !obj->hasSingletonType()) {
|
2011-05-16 16:15:37 -07:00
|
|
|
/*
|
|
|
|
* Mark as unknown any object which has had dynamic assignments to
|
|
|
|
* non-integer properties at SETELEM opcodes. This avoids making large
|
2011-08-01 22:24:29 -07:00
|
|
|
* numbers of type properties for hashmap-style objects. We don't need
|
|
|
|
* to do this for objects with singleton type, because type properties
|
|
|
|
* are only constructed for them when analyzed scripts depend on those
|
|
|
|
* specific properties.
|
2011-05-16 16:15:37 -07:00
|
|
|
*/
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t i;
|
2011-05-16 16:15:37 -07:00
|
|
|
if (js_IdIsIndex(id, &i))
|
|
|
|
return;
|
2011-07-15 10:14:07 -07:00
|
|
|
MarkTypeObjectUnknownProperties(cx, obj->type());
|
2011-05-16 16:15:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline void
|
2013-01-26 06:42:20 -08:00
|
|
|
TypeScript::SetThis(JSContext *cx, JSScript *script, Type type)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-09-01 12:20:30 -07:00
|
|
|
if (!cx->typeInferenceEnabled())
|
2011-05-09 07:12:47 -07:00
|
|
|
return;
|
2011-09-01 12:20:30 -07:00
|
|
|
JS_ASSERT(script->types);
|
2011-03-04 11:28:52 -08:00
|
|
|
|
|
|
|
/* Analyze the script regardless if -a was used. */
|
2013-02-06 21:35:16 -08:00
|
|
|
bool analyze = cx->hasOption(JSOPTION_METHODJIT_ALWAYS);
|
2011-03-04 11:28:52 -08:00
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
if (!ThisTypes(script)->hasType(type) || analyze) {
|
2013-01-18 08:23:28 -08:00
|
|
|
AutoEnterAnalysis enter(cx);
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2011-06-06 08:32:41 -07:00
|
|
|
InferSpew(ISpewOps, "externalType: setThis #%u: %s",
|
2011-07-28 09:16:53 -07:00
|
|
|
script->id(), TypeString(type));
|
|
|
|
ThisTypes(script)->addType(cx, type);
|
2011-03-03 14:07:48 -08:00
|
|
|
|
2012-07-03 10:24:35 -07:00
|
|
|
if (analyze)
|
2013-01-26 06:42:20 -08:00
|
|
|
script->ensureRanInference(cx);
|
2011-03-03 14:07:48 -08:00
|
|
|
}
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline void
|
2013-01-26 06:42:20 -08:00
|
|
|
TypeScript::SetThis(JSContext *cx, JSScript *script, const js::Value &value)
|
2011-03-15 18:22:23 -07:00
|
|
|
{
|
|
|
|
if (cx->typeInferenceEnabled())
|
2011-07-28 09:16:53 -07:00
|
|
|
SetThis(cx, script, GetValueType(cx, value));
|
2011-03-15 18:22:23 -07:00
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline void
|
2013-01-26 06:42:20 -08:00
|
|
|
TypeScript::SetLocal(JSContext *cx, JSScript *script, unsigned local, Type type)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-09-01 12:20:30 -07:00
|
|
|
if (!cx->typeInferenceEnabled())
|
2011-05-09 07:12:47 -07:00
|
|
|
return;
|
2011-09-01 12:20:30 -07:00
|
|
|
JS_ASSERT(script->types);
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
if (!LocalTypes(script, local)->hasType(type)) {
|
2013-01-18 08:23:28 -08:00
|
|
|
AutoEnterAnalysis enter(cx);
|
2011-03-03 14:07:48 -08:00
|
|
|
|
2011-06-06 08:32:41 -07:00
|
|
|
InferSpew(ISpewOps, "externalType: setLocal #%u %u: %s",
|
2011-07-28 09:16:53 -07:00
|
|
|
script->id(), local, TypeString(type));
|
|
|
|
LocalTypes(script, local)->addType(cx, type);
|
2011-03-03 14:07:48 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline void
|
2013-01-26 06:42:20 -08:00
|
|
|
TypeScript::SetLocal(JSContext *cx, JSScript *script, unsigned local, const js::Value &value)
|
2011-03-11 16:29:38 -08:00
|
|
|
{
|
|
|
|
if (cx->typeInferenceEnabled()) {
|
2011-07-15 10:14:07 -07:00
|
|
|
Type type = GetValueType(cx, value);
|
2011-07-28 09:16:53 -07:00
|
|
|
SetLocal(cx, script, local, type);
|
2011-03-11 16:29:38 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline void
|
2013-01-26 06:42:20 -08:00
|
|
|
TypeScript::SetArgument(JSContext *cx, JSScript *script, unsigned arg, Type type)
|
2011-03-03 14:07:48 -08:00
|
|
|
{
|
2011-09-01 12:20:30 -07:00
|
|
|
if (!cx->typeInferenceEnabled())
|
2011-05-09 07:12:47 -07:00
|
|
|
return;
|
2011-09-01 12:20:30 -07:00
|
|
|
JS_ASSERT(script->types);
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
if (!ArgTypes(script, arg)->hasType(type)) {
|
2013-01-18 08:23:28 -08:00
|
|
|
AutoEnterAnalysis enter(cx);
|
2011-03-03 14:07:48 -08:00
|
|
|
|
2011-06-06 08:32:41 -07:00
|
|
|
InferSpew(ISpewOps, "externalType: setArg #%u %u: %s",
|
2011-07-28 09:16:53 -07:00
|
|
|
script->id(), arg, TypeString(type));
|
|
|
|
ArgTypes(script, arg)->addType(cx, type);
|
2011-03-01 13:10:05 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline void
|
2013-01-26 06:42:20 -08:00
|
|
|
TypeScript::SetArgument(JSContext *cx, JSScript *script, unsigned arg, const js::Value &value)
|
2011-03-03 14:07:48 -08:00
|
|
|
{
|
|
|
|
if (cx->typeInferenceEnabled()) {
|
2011-07-15 10:14:07 -07:00
|
|
|
Type type = GetValueType(cx, value);
|
2011-07-28 09:16:53 -07:00
|
|
|
SetArgument(cx, script, arg, type);
|
2011-03-03 14:07:48 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// TypeCompartment
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
inline JSCompartment *
|
|
|
|
TypeCompartment::compartment()
|
|
|
|
{
|
|
|
|
return (JSCompartment *)((char *)this - offsetof(JSCompartment, types));
|
|
|
|
}
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
inline void
|
2011-07-15 10:14:07 -07:00
|
|
|
TypeCompartment::addPending(JSContext *cx, TypeConstraint *constraint, TypeSet *source, Type type)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(this == &cx->compartment->types);
|
2012-07-03 17:24:03 -07:00
|
|
|
JS_ASSERT(!cx->runtime->isHeapBusy());
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2011-06-15 19:22:27 -07:00
|
|
|
InferSpew(ISpewOps, "pending: %sC%p%s %s",
|
|
|
|
InferSpewColor(constraint), constraint, InferSpewColorReset(),
|
|
|
|
TypeString(type));
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2011-10-14 09:49:29 -07:00
|
|
|
if ((pendingCount == pendingCapacity) && !growPendingArray(cx))
|
|
|
|
return;
|
2010-10-29 08:05:55 -07:00
|
|
|
|
|
|
|
PendingWork &pending = pendingArray[pendingCount++];
|
|
|
|
pending.constraint = constraint;
|
|
|
|
pending.source = source;
|
|
|
|
pending.type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
TypeCompartment::resolvePending(JSContext *cx)
|
|
|
|
{
|
|
|
|
JS_ASSERT(this == &cx->compartment->types);
|
|
|
|
|
|
|
|
if (resolving) {
|
|
|
|
/* There is an active call further up resolving the worklist. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
resolving = true;
|
|
|
|
|
|
|
|
/* Handle all pending type registrations. */
|
|
|
|
while (pendingCount) {
|
|
|
|
const PendingWork &pending = pendingArray[--pendingCount];
|
2011-06-15 19:22:27 -07:00
|
|
|
InferSpew(ISpewOps, "resolve: %sC%p%s %s",
|
|
|
|
InferSpewColor(pending.constraint), pending.constraint,
|
|
|
|
InferSpewColorReset(), TypeString(pending.type));
|
2010-10-29 08:05:55 -07:00
|
|
|
pending.constraint->newType(cx, pending.source, pending.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
resolving = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// TypeSet
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The sets of objects and scripts in a type set grow monotonically, are usually
|
|
|
|
* empty, almost always small, and sometimes big. For empty or singleton sets,
|
|
|
|
* the pointer refers directly to the value. For sets fitting into SET_ARRAY_SIZE,
|
|
|
|
* an array of this length is used to store the elements. For larger sets, a hash
|
|
|
|
* table filled to 25%-50% of capacity is used, with collisions resolved by linear
|
|
|
|
* probing. TODO: replace these with jshashtables.
|
|
|
|
*/
|
|
|
|
const unsigned SET_ARRAY_SIZE = 8;
|
|
|
|
|
|
|
|
/* Get the capacity of a set with the given element count. */
|
|
|
|
static inline unsigned
|
|
|
|
HashSetCapacity(unsigned count)
|
|
|
|
{
|
|
|
|
JS_ASSERT(count >= 2);
|
|
|
|
|
|
|
|
if (count <= SET_ARRAY_SIZE)
|
|
|
|
return SET_ARRAY_SIZE;
|
|
|
|
|
|
|
|
unsigned log2;
|
|
|
|
JS_FLOOR_LOG2(log2, count);
|
|
|
|
return 1 << (log2 + 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute the FNV hash for the low 32 bits of v. */
|
2010-11-24 17:41:52 -08:00
|
|
|
template <class T, class KEY>
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
static inline uint32_t
|
2010-11-24 17:41:52 -08:00
|
|
|
HashKey(T v)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t nv = KEY::keyBits(v);
|
2010-10-29 08:05:55 -07:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t hash = 84696351 ^ (nv & 0xff);
|
2010-10-29 08:05:55 -07:00
|
|
|
hash = (hash * 16777619) ^ ((nv >> 8) & 0xff);
|
|
|
|
hash = (hash * 16777619) ^ ((nv >> 16) & 0xff);
|
|
|
|
return (hash * 16777619) ^ ((nv >> 24) & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-11-24 17:41:52 -08:00
|
|
|
* Insert space for an element into the specified set and grow its capacity if needed.
|
|
|
|
* returned value is an existing or new entry (NULL if new).
|
2010-10-29 08:05:55 -07:00
|
|
|
*/
|
2010-11-24 17:41:52 -08:00
|
|
|
template <class T, class U, class KEY>
|
2011-03-03 14:07:48 -08:00
|
|
|
static U **
|
2012-08-22 11:28:34 -07:00
|
|
|
HashSetInsertTry(LifoAlloc &alloc, U **&values, unsigned &count, T key)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
|
|
|
unsigned capacity = HashSetCapacity(count);
|
2010-11-24 17:41:52 -08:00
|
|
|
unsigned insertpos = HashKey<T,KEY>(key) & (capacity - 1);
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2010-11-24 17:41:52 -08:00
|
|
|
/* Whether we are converting from a fixed array to hashtable. */
|
|
|
|
bool converting = (count == SET_ARRAY_SIZE);
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2010-11-24 17:41:52 -08:00
|
|
|
if (!converting) {
|
|
|
|
while (values[insertpos] != NULL) {
|
|
|
|
if (KEY::getKey(values[insertpos]) == key)
|
2011-03-03 14:07:48 -08:00
|
|
|
return &values[insertpos];
|
2010-11-24 17:41:52 -08:00
|
|
|
insertpos = (insertpos + 1) & (capacity - 1);
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
count++;
|
|
|
|
unsigned newCapacity = HashSetCapacity(count);
|
|
|
|
|
2010-11-24 17:41:52 -08:00
|
|
|
if (newCapacity == capacity) {
|
|
|
|
JS_ASSERT(!converting);
|
2011-03-03 14:07:48 -08:00
|
|
|
return &values[insertpos];
|
2010-11-24 17:41:52 -08:00
|
|
|
}
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2012-08-22 11:28:34 -07:00
|
|
|
U **newValues = alloc.newArray<U*>(newCapacity);
|
2011-08-17 06:48:14 -07:00
|
|
|
if (!newValues)
|
2011-03-03 14:07:48 -08:00
|
|
|
return NULL;
|
|
|
|
PodZero(newValues, newCapacity);
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2010-11-24 17:41:52 -08:00
|
|
|
for (unsigned i = 0; i < capacity; i++) {
|
|
|
|
if (values[i]) {
|
|
|
|
unsigned pos = HashKey<T,KEY>(KEY::getKey(values[i])) & (newCapacity - 1);
|
|
|
|
while (newValues[pos] != NULL)
|
|
|
|
pos = (pos + 1) & (newCapacity - 1);
|
|
|
|
newValues[pos] = values[i];
|
|
|
|
}
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2010-11-24 17:41:52 -08:00
|
|
|
values = newValues;
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2010-11-24 17:41:52 -08:00
|
|
|
insertpos = HashKey<T,KEY>(key) & (newCapacity - 1);
|
|
|
|
while (values[insertpos] != NULL)
|
|
|
|
insertpos = (insertpos + 1) & (newCapacity - 1);
|
2011-03-03 14:07:48 -08:00
|
|
|
return &values[insertpos];
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-11-24 17:41:52 -08:00
|
|
|
* Insert an element into the specified set if it is not already there, returning
|
|
|
|
* an entry which is NULL if the element was not there.
|
2010-10-29 08:05:55 -07:00
|
|
|
*/
|
2010-11-24 17:41:52 -08:00
|
|
|
template <class T, class U, class KEY>
|
2011-03-03 14:07:48 -08:00
|
|
|
static inline U **
|
2012-08-22 11:28:34 -07:00
|
|
|
HashSetInsert(LifoAlloc &alloc, U **&values, unsigned &count, T key)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
|
|
|
if (count == 0) {
|
2010-11-24 17:41:52 -08:00
|
|
|
JS_ASSERT(values == NULL);
|
2010-10-29 08:05:55 -07:00
|
|
|
count++;
|
2011-03-03 14:07:48 -08:00
|
|
|
return (U **) &values;
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count == 1) {
|
2010-11-24 17:41:52 -08:00
|
|
|
U *oldData = (U*) values;
|
2011-03-03 14:07:48 -08:00
|
|
|
if (KEY::getKey(oldData) == key)
|
|
|
|
return (U **) &values;
|
|
|
|
|
2012-08-22 11:28:34 -07:00
|
|
|
values = alloc.newArray<U*>(SET_ARRAY_SIZE);
|
2011-03-03 14:07:48 -08:00
|
|
|
if (!values) {
|
|
|
|
values = (U **) oldData;
|
|
|
|
return NULL;
|
2010-11-24 17:41:52 -08:00
|
|
|
}
|
2011-03-03 14:07:48 -08:00
|
|
|
PodZero(values, SET_ARRAY_SIZE);
|
2010-11-24 17:41:52 -08:00
|
|
|
count++;
|
2010-10-29 08:05:55 -07:00
|
|
|
|
|
|
|
values[0] = oldData;
|
2011-03-03 14:07:48 -08:00
|
|
|
return &values[1];
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count <= SET_ARRAY_SIZE) {
|
|
|
|
for (unsigned i = 0; i < count; i++) {
|
2010-11-24 17:41:52 -08:00
|
|
|
if (KEY::getKey(values[i]) == key)
|
2011-03-03 14:07:48 -08:00
|
|
|
return &values[i];
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count < SET_ARRAY_SIZE) {
|
2010-11-24 17:41:52 -08:00
|
|
|
count++;
|
2011-03-03 14:07:48 -08:00
|
|
|
return &values[count - 1];
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 11:28:34 -07:00
|
|
|
return HashSetInsertTry<T,U,KEY>(alloc, values, count, key);
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2010-11-24 17:41:52 -08:00
|
|
|
/* Lookup an entry in a hash set, return NULL if it does not exist. */
|
|
|
|
template <class T, class U, class KEY>
|
|
|
|
static inline U *
|
|
|
|
HashSetLookup(U **values, unsigned count, T key)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
|
|
|
if (count == 0)
|
2010-11-24 17:41:52 -08:00
|
|
|
return NULL;
|
2010-10-29 08:05:55 -07:00
|
|
|
|
|
|
|
if (count == 1)
|
2010-11-24 17:41:52 -08:00
|
|
|
return (KEY::getKey((U *) values) == key) ? (U *) values : NULL;
|
2010-10-29 08:05:55 -07:00
|
|
|
|
|
|
|
if (count <= SET_ARRAY_SIZE) {
|
|
|
|
for (unsigned i = 0; i < count; i++) {
|
2010-11-24 17:41:52 -08:00
|
|
|
if (KEY::getKey(values[i]) == key)
|
|
|
|
return values[i];
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
2010-11-24 17:41:52 -08:00
|
|
|
return NULL;
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned capacity = HashSetCapacity(count);
|
2010-11-24 17:41:52 -08:00
|
|
|
unsigned pos = HashKey<T,KEY>(key) & (capacity - 1);
|
2010-10-29 08:05:55 -07:00
|
|
|
|
|
|
|
while (values[pos] != NULL) {
|
2010-11-24 17:41:52 -08:00
|
|
|
if (KEY::getKey(values[pos]) == key)
|
|
|
|
return values[pos];
|
2010-10-29 08:05:55 -07:00
|
|
|
pos = (pos + 1) & (capacity - 1);
|
|
|
|
}
|
|
|
|
|
2010-11-24 17:41:52 -08:00
|
|
|
return NULL;
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2012-05-07 10:12:52 -07:00
|
|
|
inline TypeObjectKey *
|
|
|
|
Type::objectKey() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isObject());
|
|
|
|
if (isTypeObject())
|
|
|
|
TypeObject::readBarrier((TypeObject *) data);
|
|
|
|
else
|
|
|
|
JSObject::readBarrier((JSObject *) (data ^ 1));
|
|
|
|
return (TypeObjectKey *) data;
|
|
|
|
}
|
|
|
|
|
2012-09-16 16:32:02 -07:00
|
|
|
inline RawObject
|
2012-05-07 10:12:52 -07:00
|
|
|
Type::singleObject() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isSingleObject());
|
|
|
|
JSObject::readBarrier((JSObject *) (data ^ 1));
|
|
|
|
return (JSObject *) (data ^ 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline TypeObject *
|
|
|
|
Type::typeObject() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isTypeObject());
|
|
|
|
TypeObject::readBarrier((TypeObject *) data);
|
|
|
|
return (TypeObject *) data;
|
|
|
|
}
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
inline bool
|
2012-11-26 13:32:45 -08:00
|
|
|
TypeSet::hasType(Type type) const
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2010-12-21 07:32:21 -08:00
|
|
|
if (unknown())
|
2010-10-29 08:05:55 -07:00
|
|
|
return true;
|
|
|
|
|
2011-07-15 10:14:07 -07:00
|
|
|
if (type.isUnknown()) {
|
2011-03-01 13:10:05 -08:00
|
|
|
return false;
|
2011-07-15 10:14:07 -07:00
|
|
|
} else if (type.isPrimitive()) {
|
2011-07-21 07:28:01 -07:00
|
|
|
return !!(flags & PrimitiveTypeFlag(type.primitive()));
|
2011-07-15 10:14:07 -07:00
|
|
|
} else if (type.isAnyObject()) {
|
2011-07-21 07:28:01 -07:00
|
|
|
return !!(flags & TYPE_FLAG_ANYOBJECT);
|
2010-11-24 17:41:52 -08:00
|
|
|
} else {
|
2011-07-21 07:28:01 -07:00
|
|
|
return !!(flags & TYPE_FLAG_ANYOBJECT) ||
|
2011-07-15 10:14:07 -07:00
|
|
|
HashSetLookup<TypeObjectKey*,TypeObjectKey,TypeObjectKey>
|
2011-07-21 07:28:01 -07:00
|
|
|
(objectSet, baseObjectCount(), type.objectKey()) != NULL;
|
2010-11-24 17:41:52 -08:00
|
|
|
}
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
inline void
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
TypeSet::setBaseObjectCount(uint32_t count)
|
2011-07-21 07:28:01 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(count <= TYPE_FLAG_OBJECT_COUNT_LIMIT);
|
|
|
|
flags = (flags & ~TYPE_FLAG_OBJECT_COUNT_MASK)
|
|
|
|
| (count << TYPE_FLAG_OBJECT_COUNT_SHIFT);
|
|
|
|
}
|
|
|
|
|
2011-03-09 11:04:36 -08:00
|
|
|
inline void
|
2011-07-15 10:14:07 -07:00
|
|
|
TypeSet::clearObjects()
|
2011-03-09 11:04:36 -08:00
|
|
|
{
|
2011-07-21 07:28:01 -07:00
|
|
|
setBaseObjectCount(0);
|
2011-03-09 11:04:36 -08:00
|
|
|
objectSet = NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
inline void
|
2011-07-15 10:14:07 -07:00
|
|
|
TypeSet::addType(JSContext *cx, Type type)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2013-01-18 08:23:28 -08:00
|
|
|
JS_ASSERT(cx->compartment->activeAnalysis);
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2010-12-21 07:32:21 -08:00
|
|
|
if (unknown())
|
2010-10-29 08:05:55 -07:00
|
|
|
return;
|
|
|
|
|
2011-07-15 10:14:07 -07:00
|
|
|
if (type.isUnknown()) {
|
2011-10-18 11:24:28 -07:00
|
|
|
flags |= TYPE_FLAG_BASE_MASK;
|
2011-07-15 10:14:07 -07:00
|
|
|
clearObjects();
|
2011-10-18 11:24:28 -07:00
|
|
|
JS_ASSERT(unknown());
|
2011-07-15 10:14:07 -07:00
|
|
|
} else if (type.isPrimitive()) {
|
|
|
|
TypeFlags flag = PrimitiveTypeFlag(type.primitive());
|
2011-07-21 07:28:01 -07:00
|
|
|
if (flags & flag)
|
2010-10-29 08:05:55 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* If we add float to a type set it is also considered to contain int. */
|
|
|
|
if (flag == TYPE_FLAG_DOUBLE)
|
|
|
|
flag |= TYPE_FLAG_INT32;
|
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
flags |= flag;
|
2010-10-29 08:05:55 -07:00
|
|
|
} else {
|
2011-07-21 07:28:01 -07:00
|
|
|
if (flags & TYPE_FLAG_ANYOBJECT)
|
2011-07-15 10:14:07 -07:00
|
|
|
return;
|
|
|
|
if (type.isAnyObject())
|
|
|
|
goto unknownObject;
|
2012-08-22 11:28:34 -07:00
|
|
|
|
|
|
|
LifoAlloc &alloc =
|
2013-03-16 20:36:37 -07:00
|
|
|
purged() ? cx->compartment->analysisLifoAlloc : cx->typeLifoAlloc();
|
2012-08-22 11:28:34 -07:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t objectCount = baseObjectCount();
|
2011-07-15 10:14:07 -07:00
|
|
|
TypeObjectKey *object = type.objectKey();
|
|
|
|
TypeObjectKey **pentry = HashSetInsert<TypeObjectKey *,TypeObjectKey,TypeObjectKey>
|
2012-08-22 11:28:34 -07:00
|
|
|
(alloc, objectSet, objectCount, object);
|
2011-08-17 06:48:14 -07:00
|
|
|
if (!pentry) {
|
|
|
|
cx->compartment->types.setPendingNukeTypes(cx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (*pentry)
|
2010-10-29 08:05:55 -07:00
|
|
|
return;
|
2011-03-03 14:07:48 -08:00
|
|
|
*pentry = object;
|
2011-03-09 11:04:36 -08:00
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
setBaseObjectCount(objectCount);
|
|
|
|
|
2011-07-31 08:40:46 -07:00
|
|
|
if (objectCount == TYPE_FLAG_OBJECT_COUNT_LIMIT)
|
|
|
|
goto unknownObject;
|
|
|
|
|
2011-07-15 10:14:07 -07:00
|
|
|
if (type.isTypeObject()) {
|
|
|
|
TypeObject *nobject = type.typeObject();
|
|
|
|
JS_ASSERT(!nobject->singleton);
|
|
|
|
if (nobject->unknownProperties())
|
|
|
|
goto unknownObject;
|
|
|
|
if (objectCount > 1) {
|
|
|
|
nobject->contribution += (objectCount - 1) * (objectCount - 1);
|
|
|
|
if (nobject->contribution >= TypeObject::CONTRIBUTION_LIMIT) {
|
|
|
|
InferSpew(ISpewOps, "limitUnknown: %sT%p%s",
|
|
|
|
InferSpewColor(this), this, InferSpewColorReset());
|
|
|
|
goto unknownObject;
|
|
|
|
}
|
2011-06-11 09:46:48 -07:00
|
|
|
}
|
2011-03-09 11:04:36 -08:00
|
|
|
}
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2011-07-15 10:14:07 -07:00
|
|
|
if (false) {
|
|
|
|
unknownObject:
|
|
|
|
type = Type::AnyObjectType();
|
2011-07-21 07:28:01 -07:00
|
|
|
flags |= TYPE_FLAG_ANYOBJECT;
|
2011-07-15 10:14:07 -07:00
|
|
|
clearObjects();
|
|
|
|
}
|
|
|
|
|
2011-06-15 19:22:27 -07:00
|
|
|
InferSpew(ISpewOps, "addType: %sT%p%s %s",
|
|
|
|
InferSpewColor(this), this, InferSpewColorReset(),
|
|
|
|
TypeString(type));
|
2011-03-17 09:42:56 -07:00
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
/* Propagate the type to all constraints. */
|
|
|
|
TypeConstraint *constraint = constraintList;
|
|
|
|
while (constraint) {
|
|
|
|
cx->compartment->types.addPending(cx, constraint, this, type);
|
|
|
|
constraint = constraint->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
cx->compartment->types.resolvePending(cx);
|
|
|
|
}
|
|
|
|
|
2011-04-11 20:10:46 -07:00
|
|
|
inline void
|
|
|
|
TypeSet::setOwnProperty(JSContext *cx, bool configured)
|
|
|
|
{
|
|
|
|
TypeFlags nflags = TYPE_FLAG_OWN_PROPERTY | (configured ? TYPE_FLAG_CONFIGURED_PROPERTY : 0);
|
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
if ((flags & nflags) == nflags)
|
2011-04-11 20:10:46 -07:00
|
|
|
return;
|
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
flags |= nflags;
|
2011-04-11 20:10:46 -07:00
|
|
|
|
|
|
|
/* Propagate the change to all constraints. */
|
|
|
|
TypeConstraint *constraint = constraintList;
|
|
|
|
while (constraint) {
|
|
|
|
constraint->newPropertyState(cx, this);
|
|
|
|
constraint = constraint->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-05 18:12:03 -07:00
|
|
|
inline unsigned
|
2012-11-26 13:32:45 -08:00
|
|
|
TypeSet::getObjectCount() const
|
2011-04-05 18:12:03 -07:00
|
|
|
{
|
2011-07-15 10:14:07 -07:00
|
|
|
JS_ASSERT(!unknownObject());
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t count = baseObjectCount();
|
2011-07-21 07:28:01 -07:00
|
|
|
if (count > SET_ARRAY_SIZE)
|
|
|
|
return HashSetCapacity(count);
|
|
|
|
return count;
|
2011-04-05 18:12:03 -07:00
|
|
|
}
|
|
|
|
|
2011-07-15 10:14:07 -07:00
|
|
|
inline TypeObjectKey *
|
2012-11-26 13:32:45 -08:00
|
|
|
TypeSet::getObject(unsigned i) const
|
2011-04-05 18:12:03 -07:00
|
|
|
{
|
2011-07-15 10:14:07 -07:00
|
|
|
JS_ASSERT(i < getObjectCount());
|
2011-07-21 07:28:01 -07:00
|
|
|
if (baseObjectCount() == 1) {
|
2011-04-05 18:12:03 -07:00
|
|
|
JS_ASSERT(i == 0);
|
2011-07-15 10:14:07 -07:00
|
|
|
return (TypeObjectKey *) objectSet;
|
2011-04-05 18:12:03 -07:00
|
|
|
}
|
|
|
|
return objectSet[i];
|
|
|
|
}
|
|
|
|
|
2012-09-16 16:32:02 -07:00
|
|
|
inline RawObject
|
2012-11-26 13:32:45 -08:00
|
|
|
TypeSet::getSingleObject(unsigned i) const
|
2011-07-15 10:14:07 -07:00
|
|
|
{
|
|
|
|
TypeObjectKey *key = getObject(i);
|
2012-01-11 00:23:05 -08:00
|
|
|
return (uintptr_t(key) & 1) ? (JSObject *)(uintptr_t(key) ^ 1) : NULL;
|
2011-07-15 10:14:07 -07:00
|
|
|
}
|
|
|
|
|
2011-05-12 20:07:23 -07:00
|
|
|
inline TypeObject *
|
2012-11-26 13:32:45 -08:00
|
|
|
TypeSet::getTypeObject(unsigned i) const
|
2011-05-12 20:07:23 -07:00
|
|
|
{
|
2011-07-15 10:14:07 -07:00
|
|
|
TypeObjectKey *key = getObject(i);
|
2012-01-11 00:23:05 -08:00
|
|
|
return (key && !(uintptr_t(key) & 1)) ? (TypeObject *) key : NULL;
|
2011-05-12 20:07:23 -07:00
|
|
|
}
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// TypeCallsite
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
inline
|
2013-03-05 10:32:12 -08:00
|
|
|
TypeCallsite::TypeCallsite(JSContext *cx, RawScript script, jsbytecode *pc,
|
2010-12-28 11:53:50 -08:00
|
|
|
bool isNew, unsigned argumentCount)
|
|
|
|
: script(script), pc(pc), isNew(isNew), argumentCount(argumentCount),
|
2011-05-20 19:33:06 -07:00
|
|
|
thisTypes(NULL), returnTypes(NULL)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-03-03 14:07:48 -08:00
|
|
|
/* Caller must check for failure. */
|
2012-08-22 11:28:34 -07:00
|
|
|
argumentTypes = cx->analysisLifoAlloc().newArray<StackTypeSet*>(argumentCount);
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
2010-11-24 17:41:52 -08:00
|
|
|
// TypeObject
|
2010-10-29 08:05:55 -07:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-01-23 11:57:55 -08:00
|
|
|
inline TypeObject::TypeObject(Class *clasp, TaggedProto proto, bool function, bool unknown)
|
2011-06-15 11:26:12 -07:00
|
|
|
{
|
2011-07-15 10:14:07 -07:00
|
|
|
PodZero(this);
|
|
|
|
|
2012-01-27 12:16:27 -08:00
|
|
|
/* Inner objects may not appear on prototype chains. */
|
2012-09-26 09:49:20 -07:00
|
|
|
JS_ASSERT_IF(proto.isObject(), !proto.toObject()->getClass()->ext.outerObject);
|
2012-01-27 12:16:27 -08:00
|
|
|
|
2013-01-23 11:57:55 -08:00
|
|
|
this->clasp = clasp;
|
2012-09-26 09:49:20 -07:00
|
|
|
this->proto = proto.raw();
|
2011-09-01 12:20:30 -07:00
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
if (function)
|
|
|
|
flags |= OBJECT_FLAG_FUNCTION;
|
|
|
|
if (unknown)
|
|
|
|
flags |= OBJECT_FLAG_UNKNOWN_MASK;
|
2011-07-15 10:14:07 -07:00
|
|
|
|
2011-08-26 08:55:00 -07:00
|
|
|
InferSpew(ISpewOps, "newObject: %s", TypeObjectString(this));
|
2011-06-15 11:26:12 -07:00
|
|
|
}
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
inline uint32_t
|
2011-07-21 07:28:01 -07:00
|
|
|
TypeObject::basePropertyCount() const
|
|
|
|
{
|
|
|
|
return (flags & OBJECT_FLAG_PROPERTY_COUNT_MASK) >> OBJECT_FLAG_PROPERTY_COUNT_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
TypeObject::setBasePropertyCount(uint32_t count)
|
2011-07-21 07:28:01 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(count <= OBJECT_FLAG_PROPERTY_COUNT_LIMIT);
|
|
|
|
flags = (flags & ~OBJECT_FLAG_PROPERTY_COUNT_MASK)
|
|
|
|
| (count << OBJECT_FLAG_PROPERTY_COUNT_SHIFT);
|
|
|
|
}
|
|
|
|
|
2012-08-22 11:28:34 -07:00
|
|
|
inline HeapTypeSet *
|
2012-12-31 12:40:21 -08:00
|
|
|
TypeObject::getProperty(JSContext *cx, RawId id, bool own)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2013-01-18 08:23:28 -08:00
|
|
|
JS_ASSERT(cx->compartment->activeAnalysis);
|
2012-12-31 12:40:21 -08:00
|
|
|
|
2010-12-18 20:44:51 -08:00
|
|
|
JS_ASSERT(JSID_IS_VOID(id) || JSID_IS_EMPTY(id) || JSID_IS_STRING(id));
|
2012-12-31 12:40:21 -08:00
|
|
|
JS_ASSERT_IF(!JSID_IS_EMPTY(id), id == IdToTypeId(id));
|
2011-04-05 18:12:03 -07:00
|
|
|
JS_ASSERT(!unknownProperties());
|
2010-10-29 08:05:55 -07:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t propertyCount = basePropertyCount();
|
2011-03-03 14:07:48 -08:00
|
|
|
Property **pprop = HashSetInsert<jsid,Property,Property>
|
2013-03-16 20:36:37 -07:00
|
|
|
(cx->typeLifoAlloc(), propertySet, propertyCount, id);
|
2011-08-17 06:48:14 -07:00
|
|
|
if (!pprop) {
|
|
|
|
cx->compartment->types.setPendingNukeTypes(cx);
|
2011-03-03 14:07:48 -08:00
|
|
|
return NULL;
|
2011-08-17 06:48:14 -07:00
|
|
|
}
|
2010-11-20 15:45:52 -08:00
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
if (!*pprop) {
|
2011-07-31 08:40:46 -07:00
|
|
|
setBasePropertyCount(propertyCount);
|
2012-04-26 12:57:29 -07:00
|
|
|
if (!addProperty(cx, id, pprop)) {
|
|
|
|
setBasePropertyCount(0);
|
|
|
|
propertySet = NULL;
|
2011-07-31 08:40:46 -07:00
|
|
|
return NULL;
|
2012-04-26 12:57:29 -07:00
|
|
|
}
|
2011-07-31 08:40:46 -07:00
|
|
|
if (propertyCount == OBJECT_FLAG_PROPERTY_COUNT_LIMIT) {
|
2011-07-21 07:28:01 -07:00
|
|
|
markUnknown(cx);
|
|
|
|
|
2012-08-22 11:28:34 -07:00
|
|
|
/*
|
|
|
|
* Return an arbitrary property in the object, as all have unknown
|
|
|
|
* type and are treated as configured.
|
|
|
|
*/
|
|
|
|
unsigned count = getPropertyCount();
|
|
|
|
for (unsigned i = 0; i < count; i++) {
|
|
|
|
if (Property *prop = getProperty(i))
|
|
|
|
return &prop->types;
|
2012-06-25 17:32:34 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 11:28:34 -07:00
|
|
|
JS_NOT_REACHED("Missing property");
|
|
|
|
return NULL;
|
2012-06-25 17:32:34 -07:00
|
|
|
}
|
|
|
|
}
|
2011-04-11 20:10:46 -07:00
|
|
|
|
2012-08-22 11:28:34 -07:00
|
|
|
HeapTypeSet *types = &(*pprop)->types;
|
2012-08-22 22:05:21 -07:00
|
|
|
if (own)
|
|
|
|
types->setOwnProperty(cx, false);
|
2011-04-11 20:10:46 -07:00
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
return types;
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 11:28:34 -07:00
|
|
|
inline HeapTypeSet *
|
2012-12-31 12:40:21 -08:00
|
|
|
TypeObject::maybeGetProperty(RawId id, JSContext *cx)
|
2011-07-15 10:14:07 -07:00
|
|
|
{
|
2011-07-21 07:28:01 -07:00
|
|
|
JS_ASSERT(JSID_IS_VOID(id) || JSID_IS_EMPTY(id) || JSID_IS_STRING(id));
|
2012-12-31 12:40:21 -08:00
|
|
|
JS_ASSERT_IF(!JSID_IS_EMPTY(id), id == IdToTypeId(id));
|
2011-07-15 10:14:07 -07:00
|
|
|
JS_ASSERT(!unknownProperties());
|
|
|
|
|
2012-12-31 12:40:21 -08:00
|
|
|
Property *prop = HashSetLookup<RawId,Property,Property>
|
2011-07-21 07:28:01 -07:00
|
|
|
(propertySet, basePropertyCount(), id);
|
|
|
|
|
|
|
|
return prop ? &prop->types : NULL;
|
2011-07-15 10:14:07 -07:00
|
|
|
}
|
|
|
|
|
2011-04-05 18:12:03 -07:00
|
|
|
inline unsigned
|
|
|
|
TypeObject::getPropertyCount()
|
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t count = basePropertyCount();
|
2011-07-21 07:28:01 -07:00
|
|
|
if (count > SET_ARRAY_SIZE)
|
|
|
|
return HashSetCapacity(count);
|
|
|
|
return count;
|
2011-04-05 18:12:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline Property *
|
|
|
|
TypeObject::getProperty(unsigned i)
|
|
|
|
{
|
2011-07-21 07:28:01 -07:00
|
|
|
JS_ASSERT(i < getPropertyCount());
|
|
|
|
if (basePropertyCount() == 1) {
|
2011-04-05 18:12:03 -07:00
|
|
|
JS_ASSERT(i == 0);
|
|
|
|
return (Property *) propertySet;
|
|
|
|
}
|
|
|
|
return propertySet[i];
|
|
|
|
}
|
|
|
|
|
2011-10-25 16:07:42 -07:00
|
|
|
inline void
|
|
|
|
TypeObject::writeBarrierPre(TypeObject *type)
|
|
|
|
{
|
|
|
|
#ifdef JSGC_INCREMENTAL
|
2011-11-14 13:03:50 -08:00
|
|
|
if (!type)
|
2011-10-25 16:07:42 -07:00
|
|
|
return;
|
|
|
|
|
2013-01-27 13:51:41 -08:00
|
|
|
JS::Zone *zone = type->zone();
|
|
|
|
if (zone->needsBarrier()) {
|
2012-02-17 11:46:11 -08:00
|
|
|
TypeObject *tmp = type;
|
2013-01-27 13:51:41 -08:00
|
|
|
MarkTypeObjectUnbarriered(zone->barrierTracer(), &tmp, "write barrier");
|
2012-02-17 11:46:11 -08:00
|
|
|
JS_ASSERT(tmp == type);
|
|
|
|
}
|
2011-10-25 16:07:42 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
TypeObject::writeBarrierPost(TypeObject *type, void *addr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-11-14 13:03:50 -08:00
|
|
|
inline void
|
|
|
|
TypeObject::readBarrier(TypeObject *type)
|
|
|
|
{
|
|
|
|
#ifdef JSGC_INCREMENTAL
|
2013-01-27 13:51:41 -08:00
|
|
|
JS::Zone *zone = type->zone();
|
|
|
|
if (zone->needsBarrier()) {
|
2012-02-17 11:46:11 -08:00
|
|
|
TypeObject *tmp = type;
|
2013-01-27 13:51:41 -08:00
|
|
|
MarkTypeObjectUnbarriered(zone->barrierTracer(), &tmp, "read barrier");
|
2012-02-17 11:46:11 -08:00
|
|
|
JS_ASSERT(tmp == type);
|
|
|
|
}
|
2011-11-14 13:03:50 -08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-10-25 16:07:42 -07:00
|
|
|
inline void
|
|
|
|
TypeNewScript::writeBarrierPre(TypeNewScript *newScript)
|
|
|
|
{
|
|
|
|
#ifdef JSGC_INCREMENTAL
|
|
|
|
if (!newScript)
|
|
|
|
return;
|
|
|
|
|
2013-01-27 13:51:41 -08:00
|
|
|
JS::Zone *zone = newScript->fun->zone();
|
|
|
|
if (zone->needsBarrier()) {
|
|
|
|
MarkObject(zone->barrierTracer(), &newScript->fun, "write barrier");
|
|
|
|
MarkShape(zone->barrierTracer(), &newScript->shape, "write barrier");
|
2011-10-25 16:07:42 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
TypeNewScript::writeBarrierPost(TypeNewScript *newScript, void *addr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
Property::Property(jsid id)
|
|
|
|
: id(id)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
Property::Property(const Property &o)
|
|
|
|
: id(o.id.get()), types(o.types)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-12-18 20:44:51 -08:00
|
|
|
} } /* namespace js::types */
|
|
|
|
|
2011-06-06 08:32:41 -07:00
|
|
|
inline bool
|
2011-10-21 14:31:01 -07:00
|
|
|
JSScript::ensureHasTypes(JSContext *cx)
|
2011-07-28 09:16:53 -07:00
|
|
|
{
|
2011-10-21 14:31:01 -07:00
|
|
|
return types || makeTypes(cx);
|
2011-07-28 09:16:53 -07:00
|
|
|
}
|
|
|
|
|
2013-01-26 06:42:20 -08:00
|
|
|
inline bool
|
|
|
|
JSScript::ensureRanAnalysis(JSContext *cx)
|
2011-07-28 09:16:53 -07:00
|
|
|
{
|
2013-01-18 08:23:28 -08:00
|
|
|
js::types::AutoEnterAnalysis aea(cx);
|
2011-12-31 06:32:04 -08:00
|
|
|
|
2013-01-26 06:42:20 -08:00
|
|
|
if (!ensureHasTypes(cx))
|
2011-12-31 06:13:01 -08:00
|
|
|
return false;
|
2013-01-26 06:42:20 -08:00
|
|
|
if (!hasAnalysis() && !makeAnalysis(cx))
|
2011-07-28 09:16:53 -07:00
|
|
|
return false;
|
2013-01-26 06:42:20 -08:00
|
|
|
JS_ASSERT(analysis()->ranBytecode());
|
2011-07-28 09:16:53 -07:00
|
|
|
return true;
|
2011-06-06 08:32:41 -07:00
|
|
|
}
|
|
|
|
|
2013-01-26 06:42:20 -08:00
|
|
|
inline bool
|
|
|
|
JSScript::ensureRanInference(JSContext *cx)
|
2011-06-06 08:32:41 -07:00
|
|
|
{
|
2013-01-26 06:42:20 -08:00
|
|
|
if (!ensureRanAnalysis(cx))
|
2011-07-28 09:16:53 -07:00
|
|
|
return false;
|
2013-01-26 06:42:20 -08:00
|
|
|
if (!analysis()->ranInference()) {
|
2013-01-18 08:23:28 -08:00
|
|
|
js::types::AutoEnterAnalysis enter(cx);
|
2013-01-26 06:42:20 -08:00
|
|
|
analysis()->analyzeTypes(cx);
|
2011-06-06 08:32:41 -07:00
|
|
|
}
|
2013-03-16 20:36:37 -07:00
|
|
|
return !analysis()->OOM() && !cx->zone()->types.pendingNukeTypes;
|
2011-07-28 09:16:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSScript::hasAnalysis()
|
|
|
|
{
|
|
|
|
return types && types->analysis;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline js::analyze::ScriptAnalysis *
|
|
|
|
JSScript::analysis()
|
|
|
|
{
|
|
|
|
JS_ASSERT(hasAnalysis());
|
|
|
|
return types->analysis;
|
2011-06-06 08:32:41 -07:00
|
|
|
}
|
|
|
|
|
2011-09-01 12:20:30 -07:00
|
|
|
inline void
|
|
|
|
JSScript::clearAnalysis()
|
|
|
|
{
|
|
|
|
if (types)
|
|
|
|
types->analysis = NULL;
|
|
|
|
}
|
|
|
|
|
2012-08-22 11:28:34 -07:00
|
|
|
inline void
|
|
|
|
JSScript::clearPropertyReadTypes()
|
|
|
|
{
|
|
|
|
if (types && types->propertyReadTypes)
|
|
|
|
types->propertyReadTypes = NULL;
|
|
|
|
}
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
inline void
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
js::analyze::ScriptAnalysis::addPushedType(JSContext *cx, uint32_t offset, uint32_t which,
|
2011-07-15 10:14:07 -07:00
|
|
|
js::types::Type type)
|
2011-04-22 07:59:45 -07:00
|
|
|
{
|
|
|
|
js::types::TypeSet *pushed = pushedTypes(offset, which);
|
|
|
|
pushed->addType(cx, type);
|
|
|
|
}
|
|
|
|
|
2012-09-24 18:08:22 -07:00
|
|
|
namespace js {
|
2012-07-02 09:25:09 -07:00
|
|
|
|
|
|
|
template <>
|
2012-09-24 18:08:22 -07:00
|
|
|
struct RootMethods<const types::Type>
|
2012-07-02 09:25:09 -07:00
|
|
|
{
|
2012-09-24 18:08:22 -07:00
|
|
|
static types::Type initial() { return types::Type::UnknownType(); }
|
2012-07-02 09:25:09 -07:00
|
|
|
static ThingRootKind kind() { return THING_ROOT_TYPE; }
|
2012-09-24 18:08:22 -07:00
|
|
|
static bool poisoned(const types::Type &v) {
|
2012-07-02 09:25:09 -07:00
|
|
|
return (v.isTypeObject() && IsPoisonedPtr(v.typeObject()))
|
|
|
|
|| (v.isSingleObject() && IsPoisonedPtr(v.singleObject()));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
2012-09-24 18:08:22 -07:00
|
|
|
struct RootMethods<types::Type>
|
2012-07-02 09:25:09 -07:00
|
|
|
{
|
2012-09-24 18:08:22 -07:00
|
|
|
static types::Type initial() { return types::Type::UnknownType(); }
|
2012-07-02 09:25:09 -07:00
|
|
|
static ThingRootKind kind() { return THING_ROOT_TYPE; }
|
2012-09-24 18:08:22 -07:00
|
|
|
static bool poisoned(const types::Type &v) {
|
2012-07-02 09:25:09 -07:00
|
|
|
return (v.isTypeObject() && IsPoisonedPtr(v.typeObject()))
|
|
|
|
|| (v.isSingleObject() && IsPoisonedPtr(v.singleObject()));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-09-24 18:08:22 -07:00
|
|
|
} // namespace js
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
template<> class AnchorPermitted<js::types::TypeObject *> { };
|
2012-07-02 09:25:09 -07:00
|
|
|
} // namespace JS
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
#endif // jsinferinlines_h___
|