diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/JavaScriptCore/runtime/JSSegmentedVariableObject.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/JavaScriptCore/runtime/JSSegmentedVariableObject.cpp')
-rw-r--r-- | Source/JavaScriptCore/runtime/JSSegmentedVariableObject.cpp | 89 |
1 files changed, 66 insertions, 23 deletions
diff --git a/Source/JavaScriptCore/runtime/JSSegmentedVariableObject.cpp b/Source/JavaScriptCore/runtime/JSSegmentedVariableObject.cpp index fedb8711b..b7487f544 100644 --- a/Source/JavaScriptCore/runtime/JSSegmentedVariableObject.cpp +++ b/Source/JavaScriptCore/runtime/JSSegmentedVariableObject.cpp @@ -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. * @@ -29,48 +29,91 @@ #include "config.h" #include "JSSegmentedVariableObject.h" -#include "Operations.h" +#include "HeapSnapshotBuilder.h" +#include "JSCInlines.h" namespace JSC { -int JSSegmentedVariableObject::findRegisterIndex(void* registerAddress) +ScopeOffset JSSegmentedVariableObject::findVariableIndex(void* variableAddress) { - ConcurrentJITLocker locker(m_lock); + ConcurrentJSLocker locker(m_lock); - for (int i = m_registers.size(); i--;) { - if (&m_registers[i] != registerAddress) + for (unsigned i = m_variables.size(); i--;) { + if (&m_variables[i] != variableAddress) continue; - return i; + return ScopeOffset(i); } CRASH(); - return -1; + return ScopeOffset(); } -int JSSegmentedVariableObject::addRegisters(int numberOfRegistersToAdd) +ScopeOffset JSSegmentedVariableObject::addVariables(unsigned numberOfVariablesToAdd, JSValue initialValue) { - ConcurrentJITLocker locker(m_lock); + ConcurrentJSLocker locker(m_lock); - ASSERT(numberOfRegistersToAdd >= 0); + size_t oldSize = m_variables.size(); + m_variables.grow(oldSize + numberOfVariablesToAdd); - size_t oldSize = m_registers.size(); - m_registers.grow(oldSize + numberOfRegistersToAdd); + for (size_t i = numberOfVariablesToAdd; i--;) + m_variables[oldSize + i].setWithoutWriteBarrier(initialValue); - for (size_t i = numberOfRegistersToAdd; i--;) - m_registers[oldSize + i].setWithoutWriteBarrier(jsUndefined()); - - return static_cast<int>(oldSize); + return ScopeOffset(oldSize); } void JSSegmentedVariableObject::visitChildren(JSCell* cell, SlotVisitor& slotVisitor) { JSSegmentedVariableObject* thisObject = jsCast<JSSegmentedVariableObject*>(cell); ASSERT_GC_OBJECT_INHERITS(thisObject, info()); - COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag); - ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren()); - JSSymbolTableObject::visitChildren(thisObject, slotVisitor); + Base::visitChildren(thisObject, slotVisitor); - for (unsigned i = thisObject->m_registers.size(); i--;) - slotVisitor.append(&thisObject->m_registers[i]); + // FIXME: We could avoid locking here if SegmentedVector was lock-free. It could be made lock-free + // relatively easily. + auto locker = holdLock(thisObject->m_lock); + for (unsigned i = thisObject->m_variables.size(); i--;) + slotVisitor.appendHidden(thisObject->m_variables[i]); +} + +void JSSegmentedVariableObject::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder) +{ + JSSegmentedVariableObject* thisObject = jsCast<JSSegmentedVariableObject*>(cell); + Base::heapSnapshot(cell, builder); + + ConcurrentJSLocker locker(thisObject->symbolTable()->m_lock); + SymbolTable::Map::iterator end = thisObject->symbolTable()->end(locker); + for (SymbolTable::Map::iterator it = thisObject->symbolTable()->begin(locker); it != end; ++it) { + SymbolTableEntry::Fast entry = it->value; + ASSERT(!entry.isNull()); + ScopeOffset offset = entry.scopeOffset(); + if (!thisObject->isValidScopeOffset(offset)) + continue; + + JSValue toValue = thisObject->variableAt(offset).get(); + if (toValue && toValue.isCell()) + builder.appendVariableNameEdge(thisObject, toValue.asCell(), it->key.get()); + } +} + +void JSSegmentedVariableObject::destroy(JSCell* cell) +{ + static_cast<JSSegmentedVariableObject*>(cell)->JSSegmentedVariableObject::~JSSegmentedVariableObject(); +} + +JSSegmentedVariableObject::JSSegmentedVariableObject(VM& vm, Structure* structure, JSScope* scope) + : JSSymbolTableObject(vm, structure, scope) + , m_classInfo(structure->classInfo()) +{ +} + +JSSegmentedVariableObject::~JSSegmentedVariableObject() +{ + RELEASE_ASSERT(!m_alreadyDestroyed); + m_alreadyDestroyed = true; +} + +void JSSegmentedVariableObject::finishCreation(VM& vm) +{ + Base::finishCreation(vm); + setSymbolTable(vm, SymbolTable::create(vm)); } } // namespace JSC |