Commit 9a71683d authored by Marja Hölttä's avatar Marja Hölttä Committed by Commit Bot

[objects.h splitting] Move String and related classes.

BUG=v8:5402,v8:6474

Cq-Include-Trybots: master.tryserver.v8:v8_linux_noi18n_rel_ng
Change-Id: Id38249fe9dc88001218aa1faa1b31c9d2f9703d1
Reviewed-on: https://chromium-review.googlesource.com/528102
Commit-Queue: Marja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45853}
parent 6a36b2a0
......@@ -719,6 +719,8 @@ action("postmortem-metadata") {
"src/objects/script-inl.h",
"src/objects/shared-function-info.h",
"src/objects/shared-function-info-inl.h",
"src/objects/string.h",
"src/objects/string-inl.h",
]
outputs = [
......@@ -1784,6 +1786,8 @@ v8_source_set("v8_base") {
"src/objects/map-inl.h",
"src/objects/map.h",
"src/objects/module-info.h",
"src/objects/name-inl.h",
"src/objects/name.h",
"src/objects/object-macros-undef.h",
"src/objects/object-macros.h",
"src/objects/regexp-match-info.h",
......@@ -1793,7 +1797,9 @@ v8_source_set("v8_base") {
"src/objects/script.h",
"src/objects/shared-function-info-inl.h",
"src/objects/shared-function-info.h",
"src/objects/string-inl.h",
"src/objects/string-table.h",
"src/objects/string.h",
"src/ostreams.cc",
"src/ostreams.h",
"src/parsing/duplicate-finder.h",
......
......@@ -9,6 +9,7 @@
#include "src/compiler/zone-stats.h"
#include "src/isolate.h"
#include "src/objects/shared-function-info.h"
#include "src/objects/string.h"
namespace v8 {
namespace internal {
......
......@@ -9,6 +9,7 @@
#include "src/compiler/operator.h"
#include "src/compiler/types.h"
#include "src/objects/map.h"
#include "src/objects/name.h"
namespace v8 {
namespace internal {
......
......@@ -7,6 +7,7 @@
#include "src/compiler/types.h"
#include "src/date.h"
#include "src/objects/string.h"
namespace v8 {
namespace internal {
......
......@@ -307,6 +307,10 @@ Handle<String> Factory::InternalizeStringWithKey(StringTableKey* key) {
return StringTable::LookupKey(isolate(), key);
}
Handle<Name> Factory::InternalizeName(Handle<Name> name) {
if (name->IsUniqueName()) return name;
return StringTable::LookupString(isolate(), Handle<String>::cast(name));
}
MaybeHandle<String> Factory::NewStringFromOneByte(Vector<const uint8_t> string,
PretenureFlag pretenure) {
......@@ -828,6 +832,10 @@ Handle<String> Factory::NewProperSubString(Handle<String> str,
return slice;
}
Handle<String> Factory::NewSubString(Handle<String> str, int begin, int end) {
if (begin == 0 && end == str->length()) return str;
return NewProperSubString(str, begin, end);
}
MaybeHandle<String> Factory::NewExternalStringFromOneByte(
const ExternalOneByteString::Resource* resource) {
......@@ -2595,6 +2603,15 @@ Handle<String> Factory::NumberToString(Handle<Object> number,
return js_string;
}
Handle<String> Factory::Uint32ToString(uint32_t value) {
Handle<String> result = NumberToString(NewNumberFromUint(value));
if (result->length() <= String::kMaxArrayIndexSize) {
uint32_t field = StringHasher::MakeArrayIndexHash(value, result->length());
result->set_hash_field(field);
}
return result;
}
Handle<DebugInfo> Factory::NewDebugInfo(Handle<SharedFunctionInfo> shared) {
DCHECK(!shared->HasDebugInfo());
......
......@@ -12,6 +12,7 @@
#include "src/objects/descriptor-array.h"
#include "src/objects/dictionary.h"
#include "src/objects/scope-info.h"
#include "src/objects/string.h"
#include "src/string-hasher.h"
namespace v8 {
......@@ -134,10 +135,7 @@ class V8_EXPORT_PRIVATE Factory final {
return StringTable::LookupString(isolate(), string);
}
Handle<Name> InternalizeName(Handle<Name> name) {
if (name->IsUniqueName()) return name;
return StringTable::LookupString(isolate(), Handle<String>::cast(name));
}
Handle<Name> InternalizeName(Handle<Name> name);
// String creation functions. Most of the string creation functions take
// a Heap::PretenureFlag argument to optionally request that they be
......@@ -254,10 +252,7 @@ class V8_EXPORT_PRIVATE Factory final {
int end);
// Create a new string object which holds a substring of a string.
Handle<String> NewSubString(Handle<String> str, int begin, int end) {
if (begin == 0 && end == str->length()) return str;
return NewProperSubString(str, begin, end);
}
Handle<String> NewSubString(Handle<String> str, int begin, int end);
// Creates a new external String object. There are two String encodings
// in the system: one-byte and two-byte. Unlike other String types, it does
......@@ -693,16 +688,7 @@ class V8_EXPORT_PRIVATE Factory final {
Handle<String> NumberToString(Handle<Object> number,
bool check_number_string_cache = true);
Handle<String> Uint32ToString(uint32_t value) {
Handle<String> result = NumberToString(NewNumberFromUint(value));
if (result->length() <= String::kMaxArrayIndexSize) {
uint32_t field =
StringHasher::MakeArrayIndexHash(value, result->length());
result->set_hash_field(field);
}
return result;
}
Handle<String> Uint32ToString(uint32_t value);
Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
......
......@@ -10,6 +10,7 @@
#include "src/base/logging.h"
#include "src/elements-kind.h"
#include "src/objects/map.h"
#include "src/objects/name.h"
#include "src/type-hints.h"
#include "src/zone/zone-containers.h"
......
......@@ -11,6 +11,7 @@
#include "src/heap/spaces.h"
#include "src/layout-descriptor.h"
#include "src/objects-body-descriptors.h"
#include "src/objects/string.h"
// This file provides base classes and auxiliary methods for defining
// static object visitors used during GC.
......
......@@ -11,6 +11,7 @@
#include "src/base/timezone-cache.h"
#include "src/objects.h"
#include "src/objects/string.h"
#include "unicode/uversion.h"
namespace U_ICU_NAMESPACE {
......
This diff is collapsed.
......@@ -6340,8 +6340,8 @@ Maybe<bool> JSReceiver::OrdinaryDefineOwnProperty(LookupIterator* it,
Handle<JSObject> object = Handle<JSObject>::cast(it->GetReceiver());
bool extensible = JSObject::IsExtensible(object);
return ValidateAndApplyPropertyDescriptor(isolate, it, extensible, desc,
&current, should_throw);
return ValidateAndApplyPropertyDescriptor(
isolate, it, extensible, desc, &current, should_throw, Handle<Name>());
}
......
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_NAME_INL_H_
#define V8_OBJECTS_NAME_INL_H_
#include "src/objects/name.h"
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
namespace v8 {
namespace internal {
CAST_ACCESSOR(Name)
CAST_ACCESSOR(Symbol)
ACCESSORS(Symbol, name, Object, kNameOffset)
SMI_ACCESSORS(Symbol, flags, kFlagsOffset)
BOOL_ACCESSORS(Symbol, flags, is_private, kPrivateBit)
BOOL_ACCESSORS(Symbol, flags, is_well_known_symbol, kWellKnownSymbolBit)
BOOL_ACCESSORS(Symbol, flags, is_public, kPublicBit)
TYPE_CHECKER(Symbol, SYMBOL_TYPE)
bool Name::IsUniqueName() const {
uint32_t type = map()->instance_type();
return (type & (kIsNotStringMask | kIsNotInternalizedMask)) !=
(kStringTag | kNotInternalizedTag);
}
uint32_t Name::hash_field() {
return READ_UINT32_FIELD(this, kHashFieldOffset);
}
void Name::set_hash_field(uint32_t value) {
WRITE_UINT32_FIELD(this, kHashFieldOffset, value);
#if V8_HOST_ARCH_64_BIT
#if V8_TARGET_LITTLE_ENDIAN
WRITE_UINT32_FIELD(this, kHashFieldSlot + kIntSize, 0);
#else
WRITE_UINT32_FIELD(this, kHashFieldSlot, 0);
#endif
#endif
}
bool Name::Equals(Name* other) {
if (other == this) return true;
if ((this->IsInternalizedString() && other->IsInternalizedString()) ||
this->IsSymbol() || other->IsSymbol()) {
return false;
}
return String::cast(this)->SlowEquals(String::cast(other));
}
bool Name::Equals(Handle<Name> one, Handle<Name> two) {
if (one.is_identical_to(two)) return true;
if ((one->IsInternalizedString() && two->IsInternalizedString()) ||
one->IsSymbol() || two->IsSymbol()) {
return false;
}
return String::SlowEquals(Handle<String>::cast(one),
Handle<String>::cast(two));
}
bool Name::IsHashFieldComputed(uint32_t field) {
return (field & kHashNotComputedMask) == 0;
}
bool Name::HasHashCode() { return IsHashFieldComputed(hash_field()); }
uint32_t Name::Hash() {
// Fast case: has hash code already been computed?
uint32_t field = hash_field();
if (IsHashFieldComputed(field)) return field >> kHashShift;
// Slow case: compute hash code and set it. Has to be a string.
return String::cast(this)->ComputeAndSetHash();
}
bool Name::IsPrivate() {
return this->IsSymbol() && Symbol::cast(this)->is_private();
}
bool Name::AsArrayIndex(uint32_t* index) {
return IsString() && String::cast(this)->AsArrayIndex(index);
}
} // namespace internal
} // namespace v8
#include "src/objects/object-macros-undef.h"
#endif // V8_OBJECTS_NAME_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_NAME_H_
#define V8_OBJECTS_NAME_H_
#include "src/objects.h"
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
namespace v8 {
namespace internal {
// The Name abstract class captures anything that can be used as a property
// name, i.e., strings and symbols. All names store a hash value.
class Name : public HeapObject {
public:
// Get and set the hash field of the name.
inline uint32_t hash_field();
inline void set_hash_field(uint32_t value);
// Tells whether the hash code has been computed.
inline bool HasHashCode();
// Returns a hash value used for the property table
inline uint32_t Hash();
// Equality operations.
inline bool Equals(Name* other);
inline static bool Equals(Handle<Name> one, Handle<Name> two);
// Conversion.
inline bool AsArrayIndex(uint32_t* index);
// If the name is private, it can only name own properties.
inline bool IsPrivate();
inline bool IsUniqueName() const;
// Return a string version of this name that is converted according to the
// rules described in ES6 section 9.2.11.
MUST_USE_RESULT static MaybeHandle<String> ToFunctionName(Handle<Name> name);
MUST_USE_RESULT static MaybeHandle<String> ToFunctionName(
Handle<Name> name, Handle<String> prefix);
DECLARE_CAST(Name)
DECLARE_PRINTER(Name)
#if V8_TRACE_MAPS
void NameShortPrint();
int NameShortPrint(Vector<char> str);
#endif
// Layout description.
static const int kHashFieldSlot = HeapObject::kHeaderSize;
#if V8_TARGET_LITTLE_ENDIAN || !V8_HOST_ARCH_64_BIT
static const int kHashFieldOffset = kHashFieldSlot;
#else
static const int kHashFieldOffset = kHashFieldSlot + kIntSize;
#endif
static const int kSize = kHashFieldSlot + kPointerSize;
// Mask constant for checking if a name has a computed hash code
// and if it is a string that is an array index. The least significant bit
// indicates whether a hash code has been computed. If the hash code has
// been computed the 2nd bit tells whether the string can be used as an
// array index.
static const int kHashNotComputedMask = 1;
static const int kIsNotArrayIndexMask = 1 << 1;
static const int kNofHashBitFields = 2;
// Shift constant retrieving hash code from hash field.
static const int kHashShift = kNofHashBitFields;
// Only these bits are relevant in the hash, since the top two are shifted
// out.
static const uint32_t kHashBitMask = 0xffffffffu >> kHashShift;
// Array index strings this short can keep their index in the hash field.
static const int kMaxCachedArrayIndexLength = 7;
// Maximum number of characters to consider when trying to convert a string
// value into an array index.
static const int kMaxArrayIndexSize = 10;
// For strings which are array indexes the hash value has the string length
// mixed into the hash, mainly to avoid a hash value of zero which would be
// the case for the string '0'. 24 bits are used for the array index value.
static const int kArrayIndexValueBits = 24;
static const int kArrayIndexLengthBits =
kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields;
STATIC_ASSERT(kArrayIndexLengthBits > 0);
STATIC_ASSERT(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits));
class ArrayIndexValueBits
: public BitField<unsigned int, kNofHashBitFields, kArrayIndexValueBits> {
}; // NOLINT
class ArrayIndexLengthBits
: public BitField<unsigned int, kNofHashBitFields + kArrayIndexValueBits,
kArrayIndexLengthBits> {}; // NOLINT
// Check that kMaxCachedArrayIndexLength + 1 is a power of two so we
// could use a mask to test if the length of string is less than or equal to
// kMaxCachedArrayIndexLength.
STATIC_ASSERT(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1));
static const unsigned int kContainsCachedArrayIndexMask =
(~static_cast<unsigned>(kMaxCachedArrayIndexLength)
<< ArrayIndexLengthBits::kShift) |
kIsNotArrayIndexMask;
// Value of empty hash field indicating that the hash is not computed.
static const int kEmptyHashField =
kIsNotArrayIndexMask | kHashNotComputedMask;
protected:
static inline bool IsHashFieldComputed(uint32_t field);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(Name);
};
// ES6 symbols.
class Symbol : public Name {
public:
// [name]: The print name of a symbol, or undefined if none.
DECL_ACCESSORS(name, Object)
DECL_INT_ACCESSORS(flags)
// [is_private]: Whether this is a private symbol. Private symbols can only
// be used to designate own properties of objects.
DECL_BOOLEAN_ACCESSORS(is_private)
// [is_well_known_symbol]: Whether this is a spec-defined well-known symbol,
// or not. Well-known symbols do not throw when an access check fails during
// a load.
DECL_BOOLEAN_ACCESSORS(is_well_known_symbol)
// [is_public]: Whether this is a symbol created by Symbol.for. Calling
// Symbol.keyFor on such a symbol simply needs to return the attached name.
DECL_BOOLEAN_ACCESSORS(is_public)
DECLARE_CAST(Symbol)
// Dispatched behavior.
DECLARE_PRINTER(Symbol)
DECLARE_VERIFIER(Symbol)
// Layout description.
static const int kNameOffset = Name::kSize;
static const int kFlagsOffset = kNameOffset + kPointerSize;
static const int kSize = kFlagsOffset + kPointerSize;
// Flags layout.
static const int kPrivateBit = 0;
static const int kWellKnownSymbolBit = 1;
static const int kPublicBit = 2;
typedef FixedBodyDescriptor<kNameOffset, kFlagsOffset, kSize> BodyDescriptor;
void SymbolShortPrint(std::ostream& os);
private:
const char* PrivateSymbolToName() const;
#if V8_TRACE_MAPS
friend class Name; // For PrivateSymbolToName.
#endif
DISALLOW_IMPLICIT_CONSTRUCTORS(Symbol);
};
} // namespace internal
} // namespace v8
#include "src/objects/object-macros-undef.h"
#endif // V8_OBJECTS_NAME_H_
......@@ -5,7 +5,9 @@
#ifndef V8_OBJECTS_SCRIPT_INL_H_
#define V8_OBJECTS_SCRIPT_INL_H_
#include "src/objects/code-cache.h"
#include "src/objects/script.h"
#include "src/objects/string-inl.h"
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
......
This diff is collapsed.
This diff is collapsed.
......@@ -4,6 +4,7 @@
#include "src/ostreams.h"
#include "src/objects.h"
#include "src/objects/string.h"
#if V8_OS_WIN
#if _MSC_VER < 1900
......
......@@ -6,6 +6,7 @@
#define V8_REGEXP_REGEXP_AST_H_
#include "src/objects.h"
#include "src/objects/string.h"
#include "src/utils.h"
#include "src/zone/zone-containers.h"
#include "src/zone/zone.h"
......
......@@ -11,6 +11,7 @@
#include "src/objects.h"
#include "src/objects/descriptor-array.h"
#include "src/objects/map.h"
#include "src/objects/name.h"
namespace v8 {
namespace internal {
......
......@@ -1243,6 +1243,8 @@
'objects/literal-objects.h',
'objects/map-inl.h',
'objects/map.h',
'objects/name-inl.h',
'objects/name.h',
'objects/module-info.h',
'objects/object-macros.h',
'objects/object-macros-undef.h',
......@@ -1253,6 +1255,8 @@
'objects/script-inl.h',
'objects/shared-function-info-inl.h',
'objects/shared-function-info.h',
'objects/string-inl.h',
'objects/string.h',
'objects/string-table.h',
'ostreams.cc',
'ostreams.h',
......@@ -2574,6 +2578,8 @@
'objects/script-inl.h',
'objects/shared-function-info.h',
'objects/shared-function-info-inl.h',
'objects/string.h',
'objects/string-inl.h',
],
},
'actions': [
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "src/compilation-info.h"
#include "src/objects/string.h"
#include "test/cctest/compiler/function-tester.h"
namespace v8 {
......
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