Commit 8f54d18b authored by Marja Hölttä's avatar Marja Hölttä Committed by Commit Bot

[objects.h splitting] Move out HashTable and related classes.

BUG=v8:5402
R=mstarzinger@chromium.org

Change-Id: I8ce43504fee83dcb6859418a526b2c7aea52e778
Reviewed-on: https://chromium-review.googlesource.com/468968
Commit-Queue: Marja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44436}
parent 0344b73e
......@@ -1700,10 +1700,15 @@ v8_source_set("v8_base") {
"src/objects-printer.cc",
"src/objects.cc",
"src/objects.h",
"src/objects/code-cache-inl.h",
"src/objects/code-cache.h",
"src/objects/compilation-cache-inl.h",
"src/objects/compilation-cache.h",
"src/objects/descriptor-array.h",
"src/objects/dictionary.h",
"src/objects/frame-array-inl.h",
"src/objects/frame-array.h",
"src/objects/hash-table.h",
"src/objects/literal-objects.cc",
"src/objects/literal-objects.h",
"src/objects/module-info.h",
......@@ -1712,6 +1717,7 @@ v8_source_set("v8_base") {
"src/objects/regexp-match-info.h",
"src/objects/scope-info.cc",
"src/objects/scope-info.h",
"src/objects/string-table.h",
"src/ostreams.cc",
"src/ostreams.h",
"src/parsing/duplicate-finder.h",
......
......@@ -8,6 +8,7 @@
#include "src/factory.h"
#include "src/globals.h"
#include "src/objects-inl.h"
#include "src/objects/compilation-cache-inl.h"
namespace v8 {
namespace internal {
......
......@@ -6,7 +6,7 @@
#define V8_COMPILATION_CACHE_H_
#include "src/allocation.h"
#include "src/objects.h"
#include "src/objects/compilation-cache.h"
namespace v8 {
namespace internal {
......
......@@ -19,6 +19,8 @@
#include "src/heap-symbols.h"
#include "src/list.h"
#include "src/objects.h"
#include "src/objects/hash-table.h"
#include "src/objects/string-table.h"
namespace v8 {
namespace internal {
......
......@@ -10,6 +10,8 @@
#include "src/heap/heap-inl.h"
#include "src/isolate.h"
#include "src/macro-assembler.h"
#include "src/objects/code-cache-inl.h"
#include "src/objects/compilation-cache-inl.h"
#include "src/utils.h"
namespace v8 {
......
......@@ -616,8 +616,6 @@ CAST_ACCESSOR(ByteArray)
CAST_ACCESSOR(BytecodeArray)
CAST_ACCESSOR(Cell)
CAST_ACCESSOR(Code)
CAST_ACCESSOR(CodeCacheHashTable)
CAST_ACCESSOR(CompilationCacheTable)
CAST_ACCESSOR(ConsString)
CAST_ACCESSOR(DeoptimizationInputData)
CAST_ACCESSOR(DeoptimizationOutputData)
......@@ -923,16 +921,6 @@ Handle<Object> StringTableShape::AsHandle(Isolate* isolate, HashTableKey* key) {
return key->AsHandle(isolate);
}
Handle<Object> CompilationCacheShape::AsHandle(Isolate* isolate,
HashTableKey* key) {
return key->AsHandle(isolate);
}
Handle<Object> CodeCacheHashTableShape::AsHandle(Isolate* isolate,
HashTableKey* key) {
return key->AsHandle(isolate);
}
template <typename Char>
class SequentialStringKey : public HashTableKey {
public:
......
......@@ -55,6 +55,8 @@
#include "src/map-updater.h"
#include "src/messages.h"
#include "src/objects-body-descriptors-inl.h"
#include "src/objects/code-cache-inl.h"
#include "src/objects/compilation-cache-inl.h"
#include "src/objects/frame-array-inl.h"
#include "src/property-descriptor.h"
#include "src/prototype.h"
......
This diff is collapsed.
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_OBJECTS_CODE_CACHE_INL_H_
#define V8_OBJECTS_CODE_CACHE_INL_H_
#include "src/objects/code-cache.h"
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
namespace v8 {
namespace internal {
CAST_ACCESSOR(CodeCacheHashTable)
Handle<Object> CodeCacheHashTableShape::AsHandle(Isolate* isolate,
HashTableKey* key) {
return key->AsHandle(isolate);
}
} // namespace internal
} // namespace v8
#include "src/objects/object-macros-undef.h"
#endif // V8_OBJECTS_CODE_CACHE_INL_H_
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_OBJECTS_CODE_CACHE_H_
#define V8_OBJECTS_CODE_CACHE_H_
#include "src/objects/hash-table.h"
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
namespace v8 {
namespace internal {
class CodeCacheHashTableShape : public BaseShape<HashTableKey*> {
public:
static inline bool IsMatch(HashTableKey* key, Object* value) {
return key->IsMatch(value);
}
static inline uint32_t Hash(HashTableKey* key) { return key->Hash(); }
static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
return key->HashForObject(object);
}
static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key);
static const int kPrefixSize = 0;
// The both the key (name + flags) and value (code object) can be derived from
// the fixed array that stores both the name and code.
// TODO(verwaest): Don't allocate a fixed array but inline name and code.
// Rewrite IsMatch to get table + index as input rather than just the raw key.
static const int kEntrySize = 1;
};
class CodeCacheHashTable
: public HashTable<CodeCacheHashTable, CodeCacheHashTableShape,
HashTableKey*> {
public:
static Handle<CodeCacheHashTable> Put(Handle<CodeCacheHashTable> table,
Handle<Name> name, Handle<Code> code);
Code* Lookup(Name* name, Code::Flags flags);
DECLARE_CAST(CodeCacheHashTable)
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCacheHashTable);
};
} // namespace internal
} // namespace v8
#include "src/objects/object-macros-undef.h"
#endif // V8_OBJECTS_CODE_CACHE_H_
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_OBJECTS_COMPILATION_CACHE_INL_H_
#define V8_OBJECTS_COMPILATION_CACHE_INL_H_
#include "src/objects/compilation-cache.h"
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
namespace v8 {
namespace internal {
CAST_ACCESSOR(CompilationCacheTable)
Handle<Object> CompilationCacheShape::AsHandle(Isolate* isolate,
HashTableKey* key) {
return key->AsHandle(isolate);
}
} // namespace internal
} // namespace v8
#include "src/objects/object-macros-undef.h"
#endif // V8_OBJECTS_COMPILATION_CACHE_INL_H_
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_OBJECTS_COMPILATION_CACHE_H_
#define V8_OBJECTS_COMPILATION_CACHE_H_
#include "src/objects/hash-table.h"
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
namespace v8 {
namespace internal {
class CompilationCacheShape : public BaseShape<HashTableKey*> {
public:
static inline bool IsMatch(HashTableKey* key, Object* value) {
return key->IsMatch(value);
}
static inline uint32_t Hash(HashTableKey* key) { return key->Hash(); }
static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
return key->HashForObject(object);
}
static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key);
static const int kPrefixSize = 0;
static const int kEntrySize = 3;
};
class InfoVectorPair {
public:
InfoVectorPair() : shared_(nullptr), vector_cell_(nullptr) {}
InfoVectorPair(SharedFunctionInfo* shared, Cell* vector_cell)
: shared_(shared), vector_cell_(vector_cell) {}
SharedFunctionInfo* shared() const { return shared_; }
Cell* vector() const { return vector_cell_; }
bool has_shared() const { return shared_ != nullptr; }
bool has_vector() const { return vector_cell_ != nullptr; }
private:
SharedFunctionInfo* shared_;
Cell* vector_cell_;
};
// This cache is used in two different variants. For regexp caching, it simply
// maps identifying info of the regexp to the cached regexp object. Scripts and
// eval code only gets cached after a second probe for the code object. To do
// so, on first "put" only a hash identifying the source is entered into the
// cache, mapping it to a lifetime count of the hash. On each call to Age all
// such lifetimes get reduced, and removed once they reach zero. If a second put
// is called while such a hash is live in the cache, the hash gets replaced by
// an actual cache entry. Age also removes stale live entries from the cache.
// Such entries are identified by SharedFunctionInfos pointing to either the
// recompilation stub, or to "old" code. This avoids memory leaks due to
// premature caching of scripts and eval strings that are never needed later.
class CompilationCacheTable
: public HashTable<CompilationCacheTable, CompilationCacheShape,
HashTableKey*> {
public:
// Find cached value for a string key, otherwise return null.
Handle<Object> Lookup(Handle<String> src, Handle<Context> context,
LanguageMode language_mode);
InfoVectorPair LookupScript(Handle<String> src, Handle<Context> context,
LanguageMode language_mode);
InfoVectorPair LookupEval(Handle<String> src,
Handle<SharedFunctionInfo> shared,
Handle<Context> native_context,
LanguageMode language_mode, int position);
Handle<Object> LookupRegExp(Handle<String> source, JSRegExp::Flags flags);
static Handle<CompilationCacheTable> Put(Handle<CompilationCacheTable> cache,
Handle<String> src,
Handle<Context> context,
LanguageMode language_mode,
Handle<Object> value);
static Handle<CompilationCacheTable> PutScript(
Handle<CompilationCacheTable> cache, Handle<String> src,
Handle<Context> context, LanguageMode language_mode,
Handle<SharedFunctionInfo> value, Handle<Cell> literals);
static Handle<CompilationCacheTable> PutEval(
Handle<CompilationCacheTable> cache, Handle<String> src,
Handle<SharedFunctionInfo> outer_info, Handle<SharedFunctionInfo> value,
Handle<Context> native_context, Handle<Cell> literals, int position);
static Handle<CompilationCacheTable> PutRegExp(
Handle<CompilationCacheTable> cache, Handle<String> src,
JSRegExp::Flags flags, Handle<FixedArray> value);
void Remove(Object* value);
void Age();
static const int kHashGenerations = 10;
DECLARE_CAST(CompilationCacheTable)
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable);
};
} // namespace internal
} // namespace v8
#include "src/objects/object-macros-undef.h"
#endif // V8_OBJECTS_COMPILATION_CACHE_H_
This diff is collapsed.
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_OBJECTS_STRING_TABLE_H_
#define V8_OBJECTS_STRING_TABLE_H_
#include "src/objects/hash-table.h"
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
namespace v8 {
namespace internal {
class StringTableShape : public BaseShape<HashTableKey*> {
public:
static inline bool IsMatch(HashTableKey* key, Object* value) {
return key->IsMatch(value);
}
static inline uint32_t Hash(HashTableKey* key) { return key->Hash(); }
static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
return key->HashForObject(object);
}
static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key);
static const int kPrefixSize = 0;
static const int kEntrySize = 1;
};
class SeqOneByteString;
// StringTable.
//
// No special elements in the prefix and the element size is 1
// because only the string itself (the key) needs to be stored.
class StringTable
: public HashTable<StringTable, StringTableShape, HashTableKey*> {
public:
// Find string in the string table. If it is not there yet, it is
// added. The return value is the string found.
V8_EXPORT_PRIVATE static Handle<String> LookupString(Isolate* isolate,
Handle<String> key);
static Handle<String> LookupKey(Isolate* isolate, HashTableKey* key);
static String* LookupKeyIfExists(Isolate* isolate, HashTableKey* key);
// Tries to internalize given string and returns string handle on success
// or an empty handle otherwise.
MUST_USE_RESULT static MaybeHandle<String> InternalizeStringIfExists(
Isolate* isolate, Handle<String> string);
// Looks up a string that is equal to the given string and returns
// string handle if it is found, or an empty handle otherwise.
MUST_USE_RESULT static MaybeHandle<String> LookupStringIfExists(
Isolate* isolate, Handle<String> str);
MUST_USE_RESULT static MaybeHandle<String> LookupTwoCharsStringIfExists(
Isolate* isolate, uint16_t c1, uint16_t c2);
static void EnsureCapacityForDeserialization(Isolate* isolate, int expected);
DECLARE_CAST(StringTable)
private:
template <bool seq_one_byte>
friend class JsonParser;
DISALLOW_IMPLICIT_CONSTRUCTORS(StringTable);
};
class StringSetShape : public BaseShape<String*> {
public:
static inline bool IsMatch(String* key, Object* value);
static inline uint32_t Hash(String* key);
static inline uint32_t HashForObject(String* key, Object* object);
static const int kPrefixSize = 0;
static const int kEntrySize = 1;
};
class StringSet : public HashTable<StringSet, StringSetShape, String*> {
public:
static Handle<StringSet> New(Isolate* isolate);
static Handle<StringSet> Add(Handle<StringSet> blacklist,
Handle<String> name);
bool Has(Handle<String> name);
DECLARE_CAST(StringSet)
};
} // namespace internal
} // namespace v8
#include "src/objects/object-macros-undef.h"
#endif // V8_OBJECTS_STRING_TABLE_H_
......@@ -1118,10 +1118,15 @@
'objects-printer.cc',
'objects.cc',
'objects.h',
'objects/code-cache.h',
'objects/code-cache-inl.h',
'objects/compilation-cache.h',
'objects/compilation-cache-inl.h',
'objects/descriptor-array.h',
'objects/dictionary.h',
'objects/frame-array.h',
'objects/frame-array-inl.h',
'objects/hash-table.h',
'objects/literal-objects.cc',
'objects/literal-objects.h',
'objects/module-info.h',
......@@ -1130,6 +1135,7 @@
'objects/regexp-match-info.h',
'objects/scope-info.cc',
'objects/scope-info.h',
'objects/string-table.h',
'ostreams.cc',
'ostreams.h',
'parsing/duplicate-finder.h',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment