summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/runtime/JSSegmentedVariableObject.h
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/JavaScriptCore/runtime/JSSegmentedVariableObject.h
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/JavaScriptCore/runtime/JSSegmentedVariableObject.h')
-rw-r--r--Source/JavaScriptCore/runtime/JSSegmentedVariableObject.h76
1 files changed, 44 insertions, 32 deletions
diff --git a/Source/JavaScriptCore/runtime/JSSegmentedVariableObject.h b/Source/JavaScriptCore/runtime/JSSegmentedVariableObject.h
index 70f877f3e..b02426c69 100644
--- a/Source/JavaScriptCore/runtime/JSSegmentedVariableObject.h
+++ b/Source/JavaScriptCore/runtime/JSSegmentedVariableObject.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -10,7 +10,7 @@
* 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.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -26,30 +26,29 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef JSSegmentedVariableObject_h
-#define JSSegmentedVariableObject_h
+#pragma once
-#include "ConcurrentJITLock.h"
+#include "ConcurrentJSLock.h"
#include "JSObject.h"
#include "JSSymbolTableObject.h"
-#include "Register.h"
#include "SymbolTable.h"
#include <wtf/SegmentedVector.h>
namespace JSC {
class LLIntOffsetsExtractor;
-class Register;
-// This is a mostly drop-in replacement for JSVariableObject, except that it preserves
+// This is a mostly drop-in replacement for JSEnvironmentRecord, except that it preserves
// the invariant that after a variable is created, its address in memory will not change
// so long as the JSSegmentedVariableObject is alive. This allows optimizations based
// on getting the address of the variable and remembering it. As well, unlike a
-// JSVariableObject, this will manage the memory for the registers itself and neither
+// JSEnvironmentRecord, this will manage the memory for the registers itself and neither
// requires nor allows for the subclasses to manage that memory. Finally,
// JSSegmentedVariableObject has its own GC tracing functionality, since it knows the
// exact dimensions of the variables array at all times.
+// Except for JSGlobalObject, subclasses of this don't call the destructor and leak memory.
+
class JSSegmentedVariableObject : public JSSymbolTableObject {
friend class JIT;
friend class LLIntOffsetsExtractor;
@@ -57,45 +56,58 @@ class JSSegmentedVariableObject : public JSSymbolTableObject {
public:
typedef JSSymbolTableObject Base;
- WriteBarrier<Unknown>& registerAt(int index) { return m_registers[index]; }
+ bool isValidScopeOffset(ScopeOffset offset)
+ {
+ return !!offset && offset.offset() < m_variables.size();
+ }
+
+ // This is not thread-safe, since m_variables is a segmented vector, and its spine can resize with
+ // malloc/free if new variables - unrelated to the one you are accessing - are added. You can get
+ // around this by grabbing m_lock, or finding some other way to get to the variable pointer (global
+ // variable access bytecode instructions will have a direct pointer already).
+ WriteBarrier<Unknown>& variableAt(ScopeOffset offset) { return m_variables[offset.offset()]; }
// This is a slow method call, which searches the register bank to find the index
// given a pointer. It will CRASH() if it does not find the register. Only use this
// in debug code (like bytecode dumping).
- JS_EXPORT_PRIVATE int findRegisterIndex(void*);
+ JS_EXPORT_PRIVATE ScopeOffset findVariableIndex(void*);
- WriteBarrier<Unknown>* assertRegisterIsInThisObject(WriteBarrier<Unknown>* registerPointer)
+ WriteBarrier<Unknown>* assertVariableIsInThisObject(WriteBarrier<Unknown>* variablePointer)
{
-#if !ASSERT_DISABLED
- findRegisterIndex(registerPointer);
-#endif
- return registerPointer;
+ if (!ASSERT_DISABLED)
+ findVariableIndex(variablePointer);
+ return variablePointer;
}
// Adds numberOfRegistersToAdd registers, initializes them to Undefined, and returns
// the index of the first one added.
- JS_EXPORT_PRIVATE int addRegisters(int numberOfRegistersToAdd);
+ JS_EXPORT_PRIVATE ScopeOffset addVariables(unsigned numberOfVariablesToAdd, JSValue);
JS_EXPORT_PRIVATE static void visitChildren(JSCell*, SlotVisitor&);
-
-protected:
- static const unsigned StructureFlags = OverridesVisitChildren | JSSymbolTableObject::StructureFlags;
-
- JSSegmentedVariableObject(VM& vm, Structure* structure, JSScope* scope)
- : JSSymbolTableObject(vm, structure, scope)
+ JS_EXPORT_PRIVATE static void heapSnapshot(JSCell*, HeapSnapshotBuilder&);
+
+ static void destroy(JSCell*);
+
+ template<typename>
+ static Subspace* subspaceFor(VM& vm)
{
+ return &vm.segmentedVariableObjectSpace;
}
+
+ const ClassInfo* classInfo() const { return m_classInfo; }
+
+protected:
+ JSSegmentedVariableObject(VM&, Structure*, JSScope*);
+
+ ~JSSegmentedVariableObject();
- void finishCreation(VM& vm)
- {
- Base::finishCreation(vm);
- }
+ void finishCreation(VM&);
- SegmentedVector<WriteBarrier<Unknown>, 16> m_registers;
- ConcurrentJITLock m_lock;
+private:
+ SegmentedVector<WriteBarrier<Unknown>, 16> m_variables;
+ ConcurrentJSLock m_lock;
+ bool m_alreadyDestroyed { false }; // We use these assertions to check that we aren't doing ancient hacks that result in this being destroyed more than once.
+ const ClassInfo* m_classInfo;
};
} // namespace JSC
-
-#endif // JSSegmentedVariableObject_h
-