Commit e9d84da4 authored by oliver@apple.com's avatar oliver@apple.com

2011-03-15 Oliver Hunt <oliver@apple.com>

        Reviewed by Geoffrey Garen.

        Introduce Local<T> to allow us to start moving to precise marking of locals
        https://bugs.webkit.org/show_bug.cgi?id=56394

        Introduce a new handle type, Local<T> and a scoping mechanism
        LocalScope to allow us to start moving towards precise marking
        of temporaries and local variables.

        We also start to use the new Local<> type in the JSON stringifier
        so that we can have some coverage of their behaviour in the initial
        checkin.

        * GNUmakefile.am:
        * JavaScriptCore.gypi:
        * JavaScriptCore.pro:
        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
        * JavaScriptCore.xcodeproj/project.pbxproj:
        * collector/handles/Handle.h:
        (JSC::::asObject):
        * collector/handles/HandleStack.cpp: Added.
        (JSC::HandleStack::HandleStack):
        (JSC::HandleStack::mark):
        (JSC::HandleStack::grow):
        * collector/handles/HandleStack.h: Added.
        (JSC::HandleStack::enterScope):
        (JSC::HandleStack::zapTo):
        (JSC::HandleStack::leaveScope):
        (JSC::HandleStack::push):
        * collector/handles/Local.h: Added.
        (JSC::Local::internalSet):
        (JSC::::Local):
        (JSC::::operator):
        (JSC::LocalStack::LocalStack):
        (JSC::LocalStack::peek):
        (JSC::LocalStack::pop):
        (JSC::LocalStack::push):
        (JSC::LocalStack::isEmpty):
        (JSC::LocalStack::size):
        * collector/handles/LocalScope.h: Added.
        (JSC::LocalScope::LocalScope):
        (JSC::LocalScope::~LocalScope):
        (JSC::LocalScope::release):
        * runtime/Heap.cpp:
        (JSC::Heap::markRoots):
        * runtime/Heap.h:
        (JSC::Heap::allocateLocalHandle):
        (JSC::Heap::handleStack):
        * runtime/JSCell.h:
        (JSC::JSCell::::getString):
        * runtime/JSGlobalData.cpp:
        (JSC::JSGlobalData::JSGlobalData):
        * runtime/JSGlobalData.h:
        (JSC::JSGlobalData::allocateLocalHandle):
        * runtime/JSONObject.cpp:
        (JSC::Stringifier::Stringifier):
        (JSC::Stringifier::stringify):
        (JSC::Stringifier::appendStringifiedValue):
        (JSC::Stringifier::Holder::Holder):
        (JSC::Walker::Walker):
        (JSC::Walker::walk):
        (JSC::JSONProtoFuncParse):
        (JSC::JSONProtoFuncStringify):
        (JSC::JSONStringify):
        * runtime/JSONObject.h:
        * runtime/MarkStack.h:
        (JSC::MarkStack::appendValues):
        (JSC::MarkStack::appendSlots):

git-svn-id: svn://svn.chromium.org/blink/trunk@81188 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 750900dc
...@@ -42,6 +42,7 @@ SET(JavaScriptCore_SOURCES ...@@ -42,6 +42,7 @@ SET(JavaScriptCore_SOURCES
bytecompiler/NodesCodegen.cpp bytecompiler/NodesCodegen.cpp
collector/handles/HandleHeap.cpp collector/handles/HandleHeap.cpp
collector/handles/HandleStack.cpp
debugger/Debugger.cpp debugger/Debugger.cpp
debugger/DebuggerActivation.cpp debugger/DebuggerActivation.cpp
......
2011-03-15 Oliver Hunt <oliver@apple.com>
Reviewed by Geoffrey Garen.
Introduce Local<T> to allow us to start moving to precise marking of locals
https://bugs.webkit.org/show_bug.cgi?id=56394
Introduce a new handle type, Local<T> and a scoping mechanism
LocalScope to allow us to start moving towards precise marking
of temporaries and local variables.
We also start to use the new Local<> type in the JSON stringifier
so that we can have some coverage of their behaviour in the initial
checkin.
* GNUmakefile.am:
* JavaScriptCore.gypi:
* JavaScriptCore.pro:
* JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
* JavaScriptCore.xcodeproj/project.pbxproj:
* collector/handles/Handle.h:
(JSC::::asObject):
* collector/handles/HandleStack.cpp: Added.
(JSC::HandleStack::HandleStack):
(JSC::HandleStack::mark):
(JSC::HandleStack::grow):
* collector/handles/HandleStack.h: Added.
(JSC::HandleStack::enterScope):
(JSC::HandleStack::zapTo):
(JSC::HandleStack::leaveScope):
(JSC::HandleStack::push):
* collector/handles/Local.h: Added.
(JSC::Local::internalSet):
(JSC::::Local):
(JSC::::operator):
(JSC::LocalStack::LocalStack):
(JSC::LocalStack::peek):
(JSC::LocalStack::pop):
(JSC::LocalStack::push):
(JSC::LocalStack::isEmpty):
(JSC::LocalStack::size):
* collector/handles/LocalScope.h: Added.
(JSC::LocalScope::LocalScope):
(JSC::LocalScope::~LocalScope):
(JSC::LocalScope::release):
* runtime/Heap.cpp:
(JSC::Heap::markRoots):
* runtime/Heap.h:
(JSC::Heap::allocateLocalHandle):
(JSC::Heap::handleStack):
* runtime/JSCell.h:
(JSC::JSCell::::getString):
* runtime/JSGlobalData.cpp:
(JSC::JSGlobalData::JSGlobalData):
* runtime/JSGlobalData.h:
(JSC::JSGlobalData::allocateLocalHandle):
* runtime/JSONObject.cpp:
(JSC::Stringifier::Stringifier):
(JSC::Stringifier::stringify):
(JSC::Stringifier::appendStringifiedValue):
(JSC::Stringifier::Holder::Holder):
(JSC::Walker::Walker):
(JSC::Walker::walk):
(JSC::JSONProtoFuncParse):
(JSC::JSONProtoFuncStringify):
(JSC::JSONStringify):
* runtime/JSONObject.h:
* runtime/MarkStack.h:
(JSC::MarkStack::appendValues):
(JSC::MarkStack::appendSlots):
2011-03-15 Gavin Barraclough <barraclough@apple.com> 2011-03-15 Gavin Barraclough <barraclough@apple.com>
Reviewed by Sam Weinig. Reviewed by Sam Weinig.
......
...@@ -115,6 +115,8 @@ javascriptcore_sources += \ ...@@ -115,6 +115,8 @@ javascriptcore_sources += \
Source/JavaScriptCore/collector/handles/Handle.h \ Source/JavaScriptCore/collector/handles/Handle.h \
Source/JavaScriptCore/collector/handles/HandleHeap.cpp \ Source/JavaScriptCore/collector/handles/HandleHeap.cpp \
Source/JavaScriptCore/collector/handles/HandleHeap.h \ Source/JavaScriptCore/collector/handles/HandleHeap.h \
Source/JavaScriptCore/collector/handles/HandleStack.cpp \
Source/JavaScriptCore/collector/handles/HandleStack.h \
Source/JavaScriptCore/config.h \ Source/JavaScriptCore/config.h \
Source/JavaScriptCore/debugger/DebuggerActivation.cpp \ Source/JavaScriptCore/debugger/DebuggerActivation.cpp \
Source/JavaScriptCore/debugger/DebuggerActivation.h \ Source/JavaScriptCore/debugger/DebuggerActivation.h \
......
...@@ -30,6 +30,9 @@ ...@@ -30,6 +30,9 @@
'collector/handles/Global.h', 'collector/handles/Global.h',
'collector/handles/Handle.h', 'collector/handles/Handle.h',
'collector/handles/HandleHeap.h', 'collector/handles/HandleHeap.h',
'collector/handles/HandleStack.h',
'collector/handles/Local.h',
'collector/handles/LocalScope.h',
'config.h', 'config.h',
'debugger/Debugger.h', 'debugger/Debugger.h',
'debugger/DebuggerActivation.h', 'debugger/DebuggerActivation.h',
...@@ -304,6 +307,7 @@ ...@@ -304,6 +307,7 @@
'bytecompiler/NodesCodegen.cpp', 'bytecompiler/NodesCodegen.cpp',
'bytecompiler/RegisterID.h', 'bytecompiler/RegisterID.h',
'collector/handles/HandleHeap.cpp', 'collector/handles/HandleHeap.cpp',
'collector/handles/HandleStack.cpp',
'debugger/Debugger.cpp', 'debugger/Debugger.cpp',
'debugger/DebuggerActivation.cpp', 'debugger/DebuggerActivation.cpp',
'debugger/DebuggerCallFrame.cpp', 'debugger/DebuggerCallFrame.cpp',
......
...@@ -73,6 +73,7 @@ SOURCES += \ ...@@ -73,6 +73,7 @@ SOURCES += \
debugger/DebuggerCallFrame.cpp \ debugger/DebuggerCallFrame.cpp \
debugger/Debugger.cpp \ debugger/Debugger.cpp \
collector/handles/HandleHeap.cpp \ collector/handles/HandleHeap.cpp \
collector/handles/HandleStack.cpp \
interpreter/CallFrame.cpp \ interpreter/CallFrame.cpp \
interpreter/Interpreter.cpp \ interpreter/Interpreter.cpp \
interpreter/RegisterFile.cpp \ interpreter/RegisterFile.cpp \
......
...@@ -1960,6 +1960,22 @@ ...@@ -1960,6 +1960,22 @@
RelativePath="..\..\collector\handles\HandleHeap.h" RelativePath="..\..\collector\handles\HandleHeap.h"
> >
</File> </File>
<File
RelativePath="..\..\collector\handles\HandleStack.cpp"
>
</File>
<File
RelativePath="..\..\collector\handles\HandleStack.h"
>
</File>
<File
RelativePath="..\..\collector\handles\Local.h"
>
</File>
<File
RelativePath="..\..\collector\handles\LocalScope.h"
>
</File>
</Filter> </Filter>
</Filter> </Filter>
<File <File
......
...@@ -375,6 +375,10 @@ ...@@ -375,6 +375,10 @@
A74DE1D0120B875600D40D5B /* ARMv7Assembler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A74DE1CB120B86D600D40D5B /* ARMv7Assembler.cpp */; }; A74DE1D0120B875600D40D5B /* ARMv7Assembler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A74DE1CB120B86D600D40D5B /* ARMv7Assembler.cpp */; };
A75706DE118A2BCF0057F88F /* JITArithmetic32_64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A75706DD118A2BCF0057F88F /* JITArithmetic32_64.cpp */; }; A75706DE118A2BCF0057F88F /* JITArithmetic32_64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A75706DD118A2BCF0057F88F /* JITArithmetic32_64.cpp */; };
A766B44F0EE8DCD1009518CA /* ExecutableAllocator.h in Headers */ = {isa = PBXBuildFile; fileRef = A7B48DB50EE74CFC00DCBDB6 /* ExecutableAllocator.h */; settings = {ATTRIBUTES = (Private, ); }; }; A766B44F0EE8DCD1009518CA /* ExecutableAllocator.h in Headers */ = {isa = PBXBuildFile; fileRef = A7B48DB50EE74CFC00DCBDB6 /* ExecutableAllocator.h */; settings = {ATTRIBUTES = (Private, ); }; };
A76BE39F132EEA7C008F7F0B /* HandleStack.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A76BE1B7132DAC68008F7F0B /* HandleStack.cpp */; };
A76BE3A0132EEA7C008F7F0B /* HandleStack.h in Headers */ = {isa = PBXBuildFile; fileRef = A76BE1B8132DAC68008F7F0B /* HandleStack.h */; settings = {ATTRIBUTES = (Private, ); }; };
A76BE3A1132EEA7C008F7F0B /* Local.h in Headers */ = {isa = PBXBuildFile; fileRef = A76BE1B5132DABF5008F7F0B /* Local.h */; settings = {ATTRIBUTES = (Private, ); }; };
A76BE3A2132EEA7C008F7F0B /* LocalScope.h in Headers */ = {isa = PBXBuildFile; fileRef = A76BE1B6132DAC24008F7F0B /* LocalScope.h */; settings = {ATTRIBUTES = (Private, ); }; };
A76C51761182748D00715B05 /* JSInterfaceJIT.h in Headers */ = {isa = PBXBuildFile; fileRef = A76C51741182748D00715B05 /* JSInterfaceJIT.h */; }; A76C51761182748D00715B05 /* JSInterfaceJIT.h in Headers */ = {isa = PBXBuildFile; fileRef = A76C51741182748D00715B05 /* JSInterfaceJIT.h */; };
A7795590101A74D500114E55 /* MarkStack.h in Headers */ = {isa = PBXBuildFile; fileRef = A779558F101A74D500114E55 /* MarkStack.h */; settings = {ATTRIBUTES = (Private, ); }; }; A7795590101A74D500114E55 /* MarkStack.h in Headers */ = {isa = PBXBuildFile; fileRef = A779558F101A74D500114E55 /* MarkStack.h */; settings = {ATTRIBUTES = (Private, ); }; };
A783A0D111A36DCA00563D20 /* JSObjectWithGlobalObject.h in Headers */ = {isa = PBXBuildFile; fileRef = A783A0D011A36DCA00563D20 /* JSObjectWithGlobalObject.h */; settings = {ATTRIBUTES = (Private, ); }; }; A783A0D111A36DCA00563D20 /* JSObjectWithGlobalObject.h in Headers */ = {isa = PBXBuildFile; fileRef = A783A0D011A36DCA00563D20 /* JSObjectWithGlobalObject.h */; settings = {ATTRIBUTES = (Private, ); }; };
...@@ -1069,6 +1073,10 @@ ...@@ -1069,6 +1073,10 @@
A74B3498102A5F8E0032AB98 /* MarkStack.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MarkStack.cpp; sourceTree = "<group>"; }; A74B3498102A5F8E0032AB98 /* MarkStack.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MarkStack.cpp; sourceTree = "<group>"; };
A74DE1CB120B86D600D40D5B /* ARMv7Assembler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ARMv7Assembler.cpp; sourceTree = "<group>"; }; A74DE1CB120B86D600D40D5B /* ARMv7Assembler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ARMv7Assembler.cpp; sourceTree = "<group>"; };
A75706DD118A2BCF0057F88F /* JITArithmetic32_64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JITArithmetic32_64.cpp; sourceTree = "<group>"; }; A75706DD118A2BCF0057F88F /* JITArithmetic32_64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JITArithmetic32_64.cpp; sourceTree = "<group>"; };
A76BE1B5132DABF5008F7F0B /* Local.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Local.h; path = collector/handles/Local.h; sourceTree = "<group>"; };
A76BE1B6132DAC24008F7F0B /* LocalScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LocalScope.h; path = collector/handles/LocalScope.h; sourceTree = "<group>"; };
A76BE1B7132DAC68008F7F0B /* HandleStack.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = HandleStack.cpp; path = collector/handles/HandleStack.cpp; sourceTree = "<group>"; };
A76BE1B8132DAC68008F7F0B /* HandleStack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HandleStack.h; path = collector/handles/HandleStack.h; sourceTree = "<group>"; };
A76C51741182748D00715B05 /* JSInterfaceJIT.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSInterfaceJIT.h; sourceTree = "<group>"; }; A76C51741182748D00715B05 /* JSInterfaceJIT.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSInterfaceJIT.h; sourceTree = "<group>"; };
A779558F101A74D500114E55 /* MarkStack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MarkStack.h; sourceTree = "<group>"; }; A779558F101A74D500114E55 /* MarkStack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MarkStack.h; sourceTree = "<group>"; };
A783A0D011A36DCA00563D20 /* JSObjectWithGlobalObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSObjectWithGlobalObject.h; sourceTree = "<group>"; }; A783A0D011A36DCA00563D20 /* JSObjectWithGlobalObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSObjectWithGlobalObject.h; sourceTree = "<group>"; };
...@@ -2140,6 +2148,10 @@ ...@@ -2140,6 +2148,10 @@
A7E4FC8812F8E4CA00AF4CF4 /* Handle.h */, A7E4FC8812F8E4CA00AF4CF4 /* Handle.h */,
A7E4FC8912F8E4CA00AF4CF4 /* HandleHeap.cpp */, A7E4FC8912F8E4CA00AF4CF4 /* HandleHeap.cpp */,
A7E4FC8A12F8E4CA00AF4CF4 /* HandleHeap.h */, A7E4FC8A12F8E4CA00AF4CF4 /* HandleHeap.h */,
A76BE1B7132DAC68008F7F0B /* HandleStack.cpp */,
A76BE1B8132DAC68008F7F0B /* HandleStack.h */,
A76BE1B5132DABF5008F7F0B /* Local.h */,
A76BE1B6132DAC24008F7F0B /* LocalScope.h */,
); );
name = handles; name = handles;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -2516,6 +2528,9 @@ ...@@ -2516,6 +2528,9 @@
A7C40C0A130B057D00D002A1 /* BlockStack.h in Headers */, A7C40C0A130B057D00D002A1 /* BlockStack.h in Headers */,
A7C40C0B130B057D00D002A1 /* SentinelLinkedList.h in Headers */, A7C40C0B130B057D00D002A1 /* SentinelLinkedList.h in Headers */,
A7C40C0C130B057D00D002A1 /* SinglyLinkedList.h in Headers */, A7C40C0C130B057D00D002A1 /* SinglyLinkedList.h in Headers */,
A76BE3A0132EEA7C008F7F0B /* HandleStack.h in Headers */,
A76BE3A1132EEA7C008F7F0B /* Local.h in Headers */,
A76BE3A2132EEA7C008F7F0B /* LocalScope.h in Headers */,
86EC9DC51328DF82002B2AD7 /* DFGByteCodeParser.h in Headers */, 86EC9DC51328DF82002B2AD7 /* DFGByteCodeParser.h in Headers */,
86EC9DC61328DF82002B2AD7 /* DFGGenerationInfo.h in Headers */, 86EC9DC61328DF82002B2AD7 /* DFGGenerationInfo.h in Headers */,
86EC9DC81328DF82002B2AD7 /* DFGGraph.h in Headers */, 86EC9DC81328DF82002B2AD7 /* DFGGraph.h in Headers */,
...@@ -2967,6 +2982,7 @@ ...@@ -2967,6 +2982,7 @@
97941A7E1302A098004A3447 /* CryptographicallyRandomNumber.cpp in Sources */, 97941A7E1302A098004A3447 /* CryptographicallyRandomNumber.cpp in Sources */,
A7E4FC9112F8E4CA00AF4CF4 /* HandleHeap.cpp in Sources */, A7E4FC9112F8E4CA00AF4CF4 /* HandleHeap.cpp in Sources */,
A7AC25BD1304D146003396DE /* MarkedBlock.cpp in Sources */, A7AC25BD1304D146003396DE /* MarkedBlock.cpp in Sources */,
A76BE39F132EEA7C008F7F0B /* HandleStack.cpp in Sources */,
86EC9DC41328DF82002B2AD7 /* DFGByteCodeParser.cpp in Sources */, 86EC9DC41328DF82002B2AD7 /* DFGByteCodeParser.cpp in Sources */,
86EC9DC71328DF82002B2AD7 /* DFGGraph.cpp in Sources */, 86EC9DC71328DF82002B2AD7 /* DFGGraph.cpp in Sources */,
86EC9DC91328DF82002B2AD7 /* DFGJITCodeGenerator.cpp in Sources */, 86EC9DC91328DF82002B2AD7 /* DFGJITCodeGenerator.cpp in Sources */,
......
...@@ -111,10 +111,19 @@ template <typename Base, typename T> struct HandleConverter { ...@@ -111,10 +111,19 @@ template <typename Base, typename T> struct HandleConverter {
}; };
template <typename Base> struct HandleConverter<Base, Unknown> { template <typename Base> struct HandleConverter<Base, Unknown> {
Handle<JSObject> asObject() const;
bool isObject() const { return jsValue().isObject(); }
bool getNumber(double number) const { return jsValue().getNumber(number); }
UString getString(ExecState*) const;
bool isUndefinedOrNull() const { return jsValue().isUndefinedOrNull(); }
private:
JSValue jsValue() const { return static_cast<const Base*>(this)->get(); }
}; };
template <typename T> class Handle : public HandleBase, public HandleConverter<Handle<T>, T> { template <typename T> class Handle : public HandleBase, public HandleConverter<Handle<T>, T> {
public: public:
template <typename A, typename B> friend class HandleConverter;
typedef typename HandleTypes<T>::ExternalType ExternalType; typedef typename HandleTypes<T>::ExternalType ExternalType;
template <typename U> Handle(Handle<U> o) template <typename U> Handle(Handle<U> o)
{ {
...@@ -144,6 +153,11 @@ private: ...@@ -144,6 +153,11 @@ private:
} }
}; };
template <typename Base> Handle<JSObject> HandleConverter<Base, Unknown>::asObject() const
{
return Handle<JSObject>::wrapSlot(static_cast<const Base*>(this)->slot());
}
template <typename T, typename U> inline bool operator==(const Handle<T>& a, const Handle<U>& b) template <typename T, typename U> inline bool operator==(const Handle<T>& a, const Handle<U>& b)
{ {
return a.get() == b.get(); return a.get() == b.get();
......
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "HandleStack.h"
#include "MarkStack.h"
namespace JSC {
HandleStack::HandleStack()
#ifndef NDEBUG
: m_scopeDepth(0)
#endif
{
grow();
}
void HandleStack::mark(MarkStack& markStack)
{
const Vector<HandleSlot>& blocks = m_blockStack.blocks();
size_t blockLength = m_blockStack.blockLength;
int end = blocks.size() - 1;
for (int i = 0; i < end; ++i) {
HandleSlot block = blocks[i];
markStack.appendSlots(block, blockLength);
}
HandleSlot block = blocks[end];
markStack.appendSlots(block, m_frame.m_next - block);
}
void HandleStack::grow()
{
HandleSlot block = m_blockStack.grow();
m_frame.m_next = block;
m_frame.m_end = block + m_blockStack.blockLength;
}
}
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef HandleStack_h
#define HandleStack_h
#include "Assertions.h"
#include "BlockStack.h"
#include "Handle.h"
#include <wtf/UnusedParam.h>
namespace JSC {
class LocalScope;
class MarkStack;
class HandleStack {
public:
class Frame {
public:
HandleSlot m_next;
HandleSlot m_end;
};
HandleStack();
void enterScope(Frame&);
void leaveScope(Frame&);
HandleSlot push();
void mark(MarkStack&);
private:
void grow();
void zapTo(Frame&);
HandleSlot findFirstAfter(HandleSlot);
#ifndef NDEBUG
size_t m_scopeDepth;
#endif
BlockStack<JSValue> m_blockStack;
Frame m_frame;
};
inline void HandleStack::enterScope(Frame& lastFrame)
{
#ifndef NDEBUG
++m_scopeDepth;
#endif
lastFrame = m_frame;
}
inline void HandleStack::zapTo(Frame& lastFrame)
{
#ifdef NDEBUG
UNUSED_PARAM(lastFrame);
#else
const Vector<HandleSlot>& blocks = m_blockStack.blocks();
if (lastFrame.m_end != m_frame.m_end) { // Zapping to a frame in a different block.
int i = blocks.size() - 1;
for ( ; blocks[i] + m_blockStack.blockLength != lastFrame.m_end; --i) {
for (int j = m_blockStack.blockLength - 1; j >= 0; --j)
blocks[i][j] = JSValue();
}
for (HandleSlot it = blocks[i] + m_blockStack.blockLength - 1; it != lastFrame.m_next - 1; --it)
*it = JSValue();
return;
}
for (HandleSlot it = m_frame.m_next - 1; it != lastFrame.m_next - 1; --it)
*it = JSValue();
#endif
}
inline void HandleStack::leaveScope(Frame& lastFrame)
{
#ifndef NDEBUG
--m_scopeDepth;
#endif
zapTo(lastFrame);
if (lastFrame.m_end != m_frame.m_end) // Popping to a frame in a different block.
m_blockStack.shrink(lastFrame.m_end);
m_frame = lastFrame;
}
inline HandleSlot HandleStack::push()
{
ASSERT(m_scopeDepth); // Creating a Local outside of a LocalScope is a memory leak.
if (m_frame.m_next == m_frame.m_end)
grow();
return m_frame.m_next++;
}
}
#endif
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef Local_h
#define Local_h
#include "Handle.h"
#include "JSGlobalData.h"
/*
A Local is a temporary handle whose lifetime is tied to a given LocalScope.
Use Locals for local values on the stack. It is an error to create a Local
outside of any LocalScope.
*/
namespace JSC {
template <typename T> class Local;
}
namespace WTF {
template<typename T> struct VectorTraits<JSC::Local<T> > {
static const bool needsDestruction = false;
static const bool needsInitialization = true;
static const bool canInitializeWithMemset = false;
static const bool canMoveWithMemcpy = true;
static const bool canCopyWithMemcpy = false;
static const bool canFillWithMemset = false;
static const bool canCompareWithMemcmp = true;
};
}
namespace JSC {
template <typename T> class Local : public Handle<T> {
friend class LocalScope;
public:
typedef typename Handle<T>::ExternalType ExternalType;
Local(JSGlobalData&, ExternalType = ExternalType());
Local(JSGlobalData&, Handle<T>);
Local(const Local<T>&); // Adopting constructor. Used to return a Local to a calling function.
Local& operator=(ExternalType);
Local& operator=(Handle<T>);
using Handle<T>::slot;
private:
Local(HandleSlot, ExternalType); // Used by LocalScope::release() to move a Local to a containing scope.
void internalSet(ExternalType value)
{
JSValue newValue(HandleTypes<T>::toJSValue(value));
HandleSlot slot = this->slot();
*slot = newValue;
}
};
template <typename T> inline Local<T>::Local(JSGlobalData& globalData, ExternalType value)
: Handle<T>(globalData.allocateLocalHandle())
{
internalSet(value);
}
template <typename T> inline Local<T>::Local(JSGlobalData& globalData, Handle<T> handle)
: Handle<T>(globalData.allocateLocalHandle())
{
internalSet(handle.get());
}
template <typename T> inline Local<T>::Local(const Local<T>& o)
: Handle<T>(o.slot())
{
const_cast<Local<T>&>(o).invalidate(); // Prevent accidental sharing.
}
template <typename T> inline Local<T>::Local(HandleSlot slot, ExternalType value)
: Handle<T>(slot, value)
{
}
template <typename T> inline Local<T>& Local<T>::operator=(ExternalType value)
{
internalSet(value);
return *this;
}
template <typename T> inline Local<T>& Local<T>::operator=(Handle<T> handle)
{
internalSet(handle.get());
return *this;
}
template <typename T, unsigned inlineCapacity = 0> class LocalStack {
typedef typename Handle<T>::ExternalType ExternalType;
public:
LocalStack(JSGlobalData& globalData)
: m_globalData(&globalData)
, m_count(0)
{
}
ExternalType peek() const
{
ASSERT(m_count > 0);
return m_stack[m_count - 1].get();
}
ExternalType pop()
{
ASSERT(m_count > 0);
return m_stack[--m_count].get();
}
void push(ExternalType value)
{
if (m_count == m_stack.size())
m_stack.append(Local<T>(*m_globalData, value));
else
m_stack[m_count] = value;
m_count++;
}
bool isEmpty() const { return !m_count; }
unsigned size() const { return m_count; }
private:
RefPtr<JSGlobalData> m_globalData;
Vector<Local<T>, inlineCapacity> m_stack;
unsigned m_count;
};
}
#endif
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef LocalScope_h
#define LocalScope_h
#include "HandleStack.h"
#include "Local.h"
namespace JSC {
/*
A LocalScope is a temporary scope in which Locals are allocated. When a
LocalScope goes out of scope, all the Locals created in it are destroyed.
LocalScope is similar in concept to NSAutoreleasePool.
*/
class JSGlobalData;
class LocalScope {
public:
explicit LocalScope(JSGlobalData&);
~LocalScope();
template <typename T> Local<T> release(Local<T>); // Destroys all other locals in the scope.
private:
HandleStack* m_handleStack;
HandleStack::Frame m_lastFrame;
};
inline LocalScope::LocalScope(JSGlobalData& globalData)
: m_handleStack(globalData.heap.handleStack())
{
m_handleStack->enterScope(m_lastFrame);
}
inline LocalScope::~LocalScope()
{
m_handleStack->leaveScope(m_lastFrame);
}
template <typename T> Local<T> LocalScope::release(Local<T> local)
{
typename Local<T>::ExternalType ptr = local.get();
m_handleStack->leaveScope(m_lastFrame);
HandleSlot slot = m_handleStack->push();
m_handleStack->enterScope(m_lastFrame);
return Local<T>(slot, ptr);
}
}
#endif
...@@ -231,8 +231,6 @@ void Heap::markRoots() ...@@ -231,8 +231,6 @@ void Heap::markRoots()
MarkedArgumentBuffer::markLists(markStack, *m_markListSet); MarkedArgumentBuffer::markLists(markStack, *m_markListSet);
if (m_globalData->exception) if (m_globalData->exception)
markStack.append(&m_globalData->exception); markStack.append(&m_globalData->exception);
if (m_globalData->firstStringifierToMark)
JSONObject::markStringifiers(markStack, m_globalData->firstStringifierToMark);
markStack.drain(); markStack.drain();
m_handleHeap.markStrongHandles(markStack); m_handleHeap.markStrongHandles(markStack);
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#define Heap_h #define Heap_h
#include "HandleHeap.h" #include "HandleHeap.h"
#include "HandleStack.h"
#include "MarkStack.h" #include "MarkStack.h"
#include "MarkedSpace.h" #include "MarkedSpace.h"
#include <wtf/Forward.h> #include <wtf/Forward.h>
...@@ -98,6 +99,9 @@ namespace JSC { ...@@ -98,6 +99,9 @@ namespace JSC {
template <typename Functor> void forEach(Functor&); template <typename Functor> void forEach(Functor&);
HandleSlot allocateGlobalHandle() { return m_handleHeap.allocate(); } HandleSlot allocateGlobalHandle() { return m_handleHeap.allocate(); }
HandleSlot allocateLocalHandle() { return m_handleStack.push(); }
HandleStack* handleStack() { return &m_handleStack; }
private: private:
friend class JSGlobalData; friend class JSGlobalData;
...@@ -132,7 +136,8 @@ namespace JSC { ...@@ -132,7 +136,8 @@ namespace JSC {
MachineThreads m_machineThreads; MachineThreads m_machineThreads;
MarkStack m_markStack; MarkStack m_markStack;
HandleHeap m_handleHeap; HandleHeap m_handleHeap;
HandleStack m_handleStack;
size_t m_extraCost; size_t m_extraCost;
}; };
......
...@@ -212,6 +212,11 @@ namespace JSC { ...@@ -212,6 +212,11 @@ namespace JSC {
return isCell() ? asCell()->getString(exec) : UString(); return isCell() ? asCell()->getString(exec) : UString();
} }
template <typename Base> UString HandleConverter<Base, Unknown>::getString(ExecState* exec) const
{
return jsValue().getString(exec);
}
inline JSObject* JSValue::getObject() const inline JSObject* JSValue::getObject() const
{ {
return isCell() ? asCell()->getObject() : 0; return isCell() ? asCell()->getObject() : 0;
......
...@@ -151,7 +151,6 @@ JSGlobalData::JSGlobalData(GlobalDataType globalDataType, ThreadStackType thread ...@@ -151,7 +151,6 @@ JSGlobalData::JSGlobalData(GlobalDataType globalDataType, ThreadStackType thread
, heap(this) , heap(this)
, globalObjectCount(0) , globalObjectCount(0)
, dynamicGlobalObject(0) , dynamicGlobalObject(0)
, firstStringifierToMark(0)
, cachedUTCOffset(NaN) , cachedUTCOffset(NaN)
, maxReentryDepth(threadStackType == ThreadStackTypeSmall ? MaxSmallThreadReentryDepth : MaxLargeThreadReentryDepth) , maxReentryDepth(threadStackType == ThreadStackTypeSmall ? MaxSmallThreadReentryDepth : MaxLargeThreadReentryDepth)
, m_regExpCache(new RegExpCache(this)) , m_regExpCache(new RegExpCache(this))
......
...@@ -57,6 +57,7 @@ namespace JSC { ...@@ -57,6 +57,7 @@ namespace JSC {
class CodeBlock; class CodeBlock;
class CommonIdentifiers; class CommonIdentifiers;
class HandleStack;
class IdentifierTable; class IdentifierTable;
class Interpreter; class Interpreter;
class JSGlobalObject; class JSGlobalObject;
...@@ -223,8 +224,6 @@ namespace JSC { ...@@ -223,8 +224,6 @@ namespace JSC {
HashSet<JSObject*> stringRecursionCheckVisitedObjects; HashSet<JSObject*> stringRecursionCheckVisitedObjects;
Stringifier* firstStringifierToMark;
double cachedUTCOffset; double cachedUTCOffset;
DSTOffsetCache dstOffsetCache; DSTOffsetCache dstOffsetCache;
...@@ -259,6 +258,7 @@ namespace JSC { ...@@ -259,6 +258,7 @@ namespace JSC {
#endif #endif
void dumpRegExpTrace(); void dumpRegExpTrace();
HandleSlot allocateGlobalHandle() { return heap.allocateGlobalHandle(); } HandleSlot allocateGlobalHandle() { return heap.allocateGlobalHandle(); }
HandleSlot allocateLocalHandle() { return heap.allocateLocalHandle(); }
private: private:
JSGlobalData(GlobalDataType, ThreadStackType); JSGlobalData(GlobalDataType, ThreadStackType);
......
...@@ -41,8 +41,6 @@ namespace JSC { ...@@ -41,8 +41,6 @@ namespace JSC {
return Structure::create(prototype, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount, &s_info); return Structure::create(prototype, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount, &s_info);
} }
static void markStringifiers(MarkStack&, Stringifier*);
protected: protected:
static const unsigned StructureFlags = OverridesGetOwnPropertySlot | JSObject::StructureFlags; static const unsigned StructureFlags = OverridesGetOwnPropertySlot | JSObject::StructureFlags;
......
...@@ -71,6 +71,12 @@ namespace JSC { ...@@ -71,6 +71,12 @@ namespace JSC {
if (count) if (count)
m_markSets.append(MarkSet(values, values + count, properties)); m_markSets.append(MarkSet(values, values + count, properties));
} }
void appendSlots(HandleSlot values, size_t count, MarkSetProperties properties = NoNullValues)
{
if (count)
m_markSets.append(MarkSet(values, values + count, properties));
}
void append(ConservativeRoots& conservativeRoots) void append(ConservativeRoots& conservativeRoots)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment