/*
- * 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
#include "HandleTypes.h"
#include "Heap.h"
#include "SamplingCounter.h"
-#include <wtf/TypeTraits.h>
namespace JSC {
+namespace DFG {
+class DesiredWriteBarrier;
+}
+
class JSCell;
-class JSGlobalData;
+class VM;
class JSGlobalObject;
template<class T> class WriteBarrierBase;
#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)
// We have a separate base class with no constructors for use in Unions.
template <typename T> class WriteBarrierBase {
public:
- void set(JSGlobalData& globalData, const JSCell* owner, T* value)
- {
- ASSERT(value);
- validateCell(value);
- setEarlyValue(globalData, 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.
m_cell = other.m_cell;
}
- void setMayBeNull(JSGlobalData& globalData, const JSCell* owner, T* value)
- {
- if (value)
- validateCell(value);
- setEarlyValue(globalData, 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(JSGlobalData&, 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
{
- if (m_cell)
- validateCell(m_cell);
- return reinterpret_cast<T*>(static_cast<void*>(m_cell));
+ // Copy m_cell to a local to avoid multiple-read issues. (See <http://webkit.org/b/110854>)
+ JSCell* cell = m_cell;
+ if (cell)
+ validateCell(cell);
+ return reinterpret_cast<T*>(static_cast<void*>(cell));
}
T* operator*() const
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; }
template <> class WriteBarrierBase<Unknown> {
public:
- void set(JSGlobalData&, 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);
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()
{
return u.slot;
}
+ 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; }
bool operator!() const { return !get(); }
};
template <typename T> class WriteBarrier : public WriteBarrierBase<T> {
+ WTF_MAKE_FAST_ALLOCATED;
public:
WriteBarrier()
{
this->setWithoutWriteBarrier(0);
}
- WriteBarrier(JSGlobalData& globalData, const JSCell* owner, T* value)
+ WriteBarrier(VM& vm, const JSCell* owner, T* value)
{
- this->set(globalData, owner, value);
+ this->set(vm, owner, value);
+ }
+
+ WriteBarrier(DFG::DesiredWriteBarrier&, T* value)
+ {
+ ASSERT(isCompilationThread());
+ this->setWithoutWriteBarrier(value);
}
enum MayBeNullTag { MayBeNull };
- WriteBarrier(JSGlobalData& globalData, const JSCell* owner, T* value, MayBeNullTag)
+ WriteBarrier(VM& vm, const JSCell* owner, T* value, MayBeNullTag)
{
- this->setMayBeNull(globalData, owner, value);
+ this->setMayBeNull(vm, owner, value);
}
};
template <> class WriteBarrier<Unknown> : public WriteBarrierBase<Unknown> {
+ WTF_MAKE_FAST_ALLOCATED;
public:
WriteBarrier()
{
this->setWithoutWriteBarrier(JSValue());
}
- WriteBarrier(JSGlobalData& globalData, const JSCell* owner, JSValue value)
+ WriteBarrier(VM& vm, const JSCell* owner, JSValue value)
{
- this->set(globalData, owner, value);
+ this->set(vm, owner, value);
+ }
+
+ WriteBarrier(DFG::DesiredWriteBarrier&, JSValue value)
+ {
+ ASSERT(isCompilationThread());
+ this->setWithoutWriteBarrier(value);
}
};
return lhs.get() == rhs.get();
}
-// MarkStack functions
-
-template<typename T> inline void MarkStack::append(WriteBarrierBase<T>* slot)
-{
- internalAppend(*slot->slot());
-}
-
-ALWAYS_INLINE void MarkStack::appendValues(WriteBarrierBase<Unknown>* barriers, size_t count)
-{
- append(barriers->slot(), count);
-}
-
} // namespace JSC
#endif // WriteBarrier_h