Skip to content

Commit

Permalink
some changes for SharedArrayBuffer
Browse files Browse the repository at this point in the history
- Due to spec change, SharedArrayBuffer is not transferrable, remove related code
- Hardening the allocation path for OOM case
- Fix a possible race issue in waiter list
- Enable by default
  • Loading branch information
leirocks committed May 17, 2017
1 parent e800a81 commit a4e46c7
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 157 deletions.
2 changes: 2 additions & 0 deletions bin/ch/DbgController.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ var controllerObj = (function () {
"#__proto__",
"Array",
"ArrayBuffer",
"Atomics",
"Boolean",
"CollectGarbage",
"console",
Expand Down Expand Up @@ -105,6 +106,7 @@ var controllerObj = (function () {
"Reflect",
"RegExp",
"Set",
"SharedArrayBuffer",
"String",
"Symbol",
"SyntaxError",
Expand Down
7 changes: 2 additions & 5 deletions lib/Common/ConfigFlagsList.h
Original file line number Diff line number Diff line change
Expand Up @@ -586,11 +586,8 @@ PHASE(All)
#define DEFAULT_CONFIG_ES7ValuesEntries (true)
#define DEFAULT_CONFIG_ESObjectGetOwnPropertyDescriptors (true)

#ifdef COMPILE_DISABLE_ESSharedArrayBuffer
#define DEFAULT_CONFIG_ESSharedArrayBuffer (false)
#else
#define DEFAULT_CONFIG_ESSharedArrayBuffer (false)
#endif
#define DEFAULT_CONFIG_ESSharedArrayBuffer (true)

#define DEFAULT_CONFIG_ES6Verbose (false)
#define DEFAULT_CONFIG_ES6All (false)
// ES6 DEFAULT BEHAVIOR
Expand Down
15 changes: 10 additions & 5 deletions lib/Common/Memory/Allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ struct AllocatorInfo
template <typename TAllocator>
struct ForceNonLeafAllocator
{
static const bool FakeZeroLengthArray = true;
typedef TAllocator AllocatorType;
};

Expand All @@ -235,6 +236,7 @@ template <typename TAllocator>
struct ForceLeafAllocator
{
typedef TAllocator AllocatorType;
static const bool FakeZeroLengthArray = true;
};

// Optional AllocatorDelete flags
Expand Down Expand Up @@ -382,16 +384,19 @@ void DestructArray(size_t count, T* obj)
template <typename TAllocator, typename T>
void DeleteArray(typename AllocatorInfo<TAllocator, T>::AllocatorType * allocator, size_t count, T * obj)
{
if (count == 0)
if (count == 0 && AllocatorInfo<TAllocator, T>::AllocatorType::FakeZeroLengthArray)
{
return;
}

DestructArray(count, obj);
if (count != 0)
{
DestructArray(count, obj);

// DeleteArray can only be called when an array is allocated successfully.
// So the add should never overflow
Assert(count * sizeof(T) / count == sizeof(T));
// DeleteArray can only be called when an array is allocated successfully.
// So the add should never overflow
Assert(count * sizeof(T) / count == sizeof(T));
}

auto freeFunc = AllocatorInfo<TAllocator, T>::AllocatorFunc::GetFreeFunc();
(allocator->*freeFunc)((void *)obj, sizeof(T) * count);
Expand Down
18 changes: 15 additions & 3 deletions lib/Common/Memory/Recycler.h
Original file line number Diff line number Diff line change
Expand Up @@ -2318,9 +2318,21 @@ class TypeAllocatorFunc<Recycler, T *> : public _RecyclerAllocatorFunc<_Recycler
#endif

// Dummy class to choose the allocation function
class RecyclerLeafAllocator;
class RecyclerNonLeafAllocator;
class RecyclerWriteBarrierAllocator;
class RecyclerLeafAllocator
{
public:
static const bool FakeZeroLengthArray = true;
};
class RecyclerNonLeafAllocator
{
public:
static const bool FakeZeroLengthArray = true;
};
class RecyclerWriteBarrierAllocator
{
public:
static const bool FakeZeroLengthArray = true;
};

// Choose RecyclerLeafAllocator / RecyclerNonLeafAllocator based on "bool isLeaf"
template <bool isLeaf>
Expand Down
12 changes: 2 additions & 10 deletions lib/Runtime/Language/JavascriptOperators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5431,16 +5431,8 @@ namespace Js

Var JavascriptOperators::NewVarFromDetachedState(DetachedStateBase* state, JavascriptLibrary *library)
{
switch (state->GetTypeId())
{
case TypeIds_SharedArrayBuffer:
return Js::SharedArrayBuffer::NewFromSharedState(state, library);
case TypeIds_ArrayBuffer:
return Js::ArrayBuffer::NewFromDetachedState(state, library);
default:
AssertMsg(false, "We should explicitly have a case statement for each object which has detached state.");
return nullptr;
}
AssertOrFailFastMsg(state->GetTypeId() == TypeIds_ArrayBuffer, "We should only re-activate detached ArrayBuffer");
return Js::ArrayBuffer::NewFromDetachedState(state, library);
}

DynamicType *
Expand Down
4 changes: 2 additions & 2 deletions lib/Runtime/Library/ArrayBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ namespace Js
return IsValidAsmJsBufferLengthAlgo(length, forceCheck);
}

bool JavascriptArrayBuffer::IsValidVirtualBufferLength(uint length)
bool JavascriptArrayBuffer::IsValidVirtualBufferLength(uint length) const
{
#if ENABLE_FAST_ARRAYBUFFER
return !PHASE_OFF1(Js::TypedArrayVirtualPhase) && IsValidAsmJsBufferLengthAlgo(length, true);
Expand Down Expand Up @@ -860,7 +860,7 @@ namespace Js
return result;
}

bool WebAssemblyArrayBuffer::IsValidVirtualBufferLength(uint length)
bool WebAssemblyArrayBuffer::IsValidVirtualBufferLength(uint length) const
{
#if ENABLE_FAST_ARRAYBUFFER
return true;
Expand Down
6 changes: 3 additions & 3 deletions lib/Runtime/Library/ArrayBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace Js
virtual void AddParent(ArrayBufferParent* parent) { }
virtual uint32 GetByteLength() const = 0;
virtual BYTE* GetBuffer() const = 0;
virtual bool IsValidVirtualBufferLength(uint length) { return false; }
virtual bool IsValidVirtualBufferLength(uint length) const { return false; };

static bool Is(Var value);
static ArrayBufferBase* FromVar(Var value);
Expand Down Expand Up @@ -255,7 +255,7 @@ namespace Js

static bool IsValidAsmJsBufferLengthAlgo(uint length, bool forceCheck);
virtual bool IsValidAsmJsBufferLength(uint length, bool forceCheck = false) override;
virtual bool IsValidVirtualBufferLength(uint length) override;
virtual bool IsValidVirtualBufferLength(uint length) const override;

virtual ArrayBuffer * TransferInternal(DECLSPEC_GUARD_OVERFLOW uint32 newBufferLength) override;

Expand Down Expand Up @@ -286,7 +286,7 @@ namespace Js
DEFINE_MARSHAL_OBJECT_TO_SCRIPT_CONTEXT(WebAssemblyArrayBuffer);
public:
static WebAssemblyArrayBuffer* Create(byte* buffer, DECLSPEC_GUARD_OVERFLOW uint32 length, DynamicType * type);
virtual bool IsValidVirtualBufferLength(uint length) override;
virtual bool IsValidVirtualBufferLength(uint length) const override;
virtual ArrayBuffer * TransferInternal(DECLSPEC_GUARD_OVERFLOW uint32 newBufferLength) override;
};

Expand Down
Loading

0 comments on commit a4e46c7

Please sign in to comment.