summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/runtime/WriteBarrier.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/JavaScriptCore/runtime/WriteBarrier.h')
-rw-r--r--Source/JavaScriptCore/runtime/WriteBarrier.h88
1 files changed, 36 insertions, 52 deletions
diff --git a/Source/JavaScriptCore/runtime/WriteBarrier.h b/Source/JavaScriptCore/runtime/WriteBarrier.h
index fe07cf532..b727d185e 100644
--- a/Source/JavaScriptCore/runtime/WriteBarrier.h
+++ b/Source/JavaScriptCore/runtime/WriteBarrier.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2011, 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -30,10 +30,13 @@
#include "HandleTypes.h"
#include "Heap.h"
#include "SamplingCounter.h"
-#include <wtf/TypeTraits.h>
namespace JSC {
+namespace DFG {
+class DesiredWriteBarrier;
+}
+
class JSCell;
class VM;
class JSGlobalObject;
@@ -47,7 +50,7 @@ JS_EXPORT_PRIVATE void slowValidateCell(JSGlobalObject*);
#if ENABLE(GC_VALIDATION)
template<class T> inline void validateCell(T cell)
{
- ASSERT_GC_OBJECT_INHERITS(cell, &WTF::RemovePointer<T>::Type::s_info);
+ ASSERT_GC_OBJECT_INHERITS(cell, std::remove_pointer<T>::type::info());
}
template<> inline void validateCell<JSCell*>(JSCell* cell)
@@ -68,12 +71,7 @@ template<class T> inline void validateCell(T)
// We have a separate base class with no constructors for use in Unions.
template <typename T> class WriteBarrierBase {
public:
- void set(VM& vm, const JSCell* owner, T* value)
- {
- ASSERT(value);
- validateCell(value);
- setEarlyValue(vm, owner, value);
- }
+ void set(VM&, const JSCell* owner, T* value);
// This is meant to be used like operator=, but is called copyFrom instead, in
// order to kindly inform the C++ compiler that its advice is not appreciated.
@@ -82,20 +80,11 @@ public:
m_cell = other.m_cell;
}
- void setMayBeNull(VM& vm, const JSCell* owner, T* value)
- {
- if (value)
- validateCell(value);
- setEarlyValue(vm, owner, value);
- }
+ void setMayBeNull(VM&, const JSCell* owner, T* value);
// Should only be used by JSCell during early initialisation
// when some basic types aren't yet completely instantiated
- void setEarlyValue(VM&, const JSCell* owner, T* value)
- {
- this->m_cell = reinterpret_cast<JSCell*>(value);
- Heap::writeBarrier(owner, this->m_cell);
- }
+ void setEarlyValue(VM&, const JSCell* owner, T* value);
T* get() const
{
@@ -122,10 +111,9 @@ public:
void clear() { m_cell = 0; }
- JSCell** slot() { return &m_cell; }
+ T** slot() { return reinterpret_cast<T**>(&m_cell); }
- typedef T* (WriteBarrierBase::*UnspecifiedBoolType);
- operator UnspecifiedBoolType*() const { return m_cell ? reinterpret_cast<UnspecifiedBoolType*>(1) : 0; }
+ explicit operator bool() const { return m_cell; }
bool operator!() const { return !m_cell; }
@@ -137,9 +125,7 @@ public:
this->m_cell = reinterpret_cast<JSCell*>(value);
}
-#if ENABLE(GC_VALIDATION)
T* unvalidatedGet() const { return reinterpret_cast<T*>(static_cast<void*>(m_cell)); }
-#endif
private:
JSCell* m_cell;
@@ -147,12 +133,7 @@ private:
template <> class WriteBarrierBase<Unknown> {
public:
- void set(VM&, const JSCell* owner, JSValue value)
- {
- m_value = JSValue::encode(value);
- Heap::writeBarrier(owner, value);
- }
-
+ void set(VM&, const JSCell* owner, JSValue);
void setWithoutWriteBarrier(JSValue value)
{
m_value = JSValue::encode(value);
@@ -164,26 +145,22 @@ public:
}
void clear() { m_value = JSValue::encode(JSValue()); }
void setUndefined() { m_value = JSValue::encode(jsUndefined()); }
+ void setStartingValue(JSValue value) { m_value = JSValue::encode(value); }
bool isNumber() const { return get().isNumber(); }
bool isObject() const { return get().isObject(); }
bool isNull() const { return get().isNull(); }
bool isGetterSetter() const { return get().isGetterSetter(); }
+ bool isCustomGetterSetter() const { return get().isCustomGetterSetter(); }
- JSValue* slot()
+ JSValue* slot() const
{
- union {
- EncodedJSValue* v;
- JSValue* slot;
- } u;
- u.v = &m_value;
- return u.slot;
+ return bitwise_cast<JSValue*>(&m_value);
}
int32_t* tagPointer() { return &bitwise_cast<EncodedValueDescriptor*>(&m_value)->asBits.tag; }
int32_t* payloadPointer() { return &bitwise_cast<EncodedValueDescriptor*>(&m_value)->asBits.payload; }
- typedef JSValue (WriteBarrierBase::*UnspecifiedBoolType);
- operator UnspecifiedBoolType*() const { return get() ? reinterpret_cast<UnspecifiedBoolType*>(1) : 0; }
+ explicit operator bool() const { return !!get(); }
bool operator!() const { return !get(); }
private:
@@ -191,6 +168,7 @@ private:
};
template <typename T> class WriteBarrier : public WriteBarrierBase<T> {
+ WTF_MAKE_FAST_ALLOCATED;
public:
WriteBarrier()
{
@@ -202,6 +180,12 @@ public:
this->set(vm, owner, value);
}
+ WriteBarrier(DFG::DesiredWriteBarrier&, T* value)
+ {
+ ASSERT(isCompilationThread());
+ this->setWithoutWriteBarrier(value);
+ }
+
enum MayBeNullTag { MayBeNull };
WriteBarrier(VM& vm, const JSCell* owner, T* value, MayBeNullTag)
{
@@ -209,17 +193,29 @@ public:
}
};
+enum UndefinedWriteBarrierTagType { UndefinedWriteBarrierTag };
template <> class WriteBarrier<Unknown> : public WriteBarrierBase<Unknown> {
+ WTF_MAKE_FAST_ALLOCATED;
public:
WriteBarrier()
{
this->setWithoutWriteBarrier(JSValue());
}
+ WriteBarrier(UndefinedWriteBarrierTagType)
+ {
+ this->setWithoutWriteBarrier(jsUndefined());
+ }
WriteBarrier(VM& vm, const JSCell* owner, JSValue value)
{
this->set(vm, owner, value);
}
+
+ WriteBarrier(DFG::DesiredWriteBarrier&, JSValue value)
+ {
+ ASSERT(isCompilationThread());
+ this->setWithoutWriteBarrier(value);
+ }
};
template <typename U, typename V> inline bool operator==(const WriteBarrierBase<U>& lhs, const WriteBarrierBase<V>& rhs)
@@ -227,18 +223,6 @@ template <typename U, typename V> inline bool operator==(const WriteBarrierBase<
return lhs.get() == rhs.get();
}
-// SlotVisitor functions
-
-template<typename T> inline void SlotVisitor::append(WriteBarrierBase<T>* slot)
-{
- internalAppend(*slot->slot());
-}
-
-ALWAYS_INLINE void SlotVisitor::appendValues(WriteBarrierBase<Unknown>* barriers, size_t count)
-{
- append(barriers->slot(), count);
-}
-
} // namespace JSC
#endif // WriteBarrier_h