Commit 1a0efd80 authored by Benoît Lizé's avatar Benoît Lizé Committed by Commit Bot

Report the per-isolate total size of scripts source.

As with other code size stats, this doesn't distinguish between live and
dead objects, and doesn't scan the young generation.

Also make ExternalString::is_short() const.

Bug: chromium:837659
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
Change-Id: I72815edb719ba61d9727e226ff1da0fc4af22a24
Reviewed-on: https://chromium-review.googlesource.com/1032994
Commit-Queue: Benoit L <lizeb@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52955}
parent 5db17032
......@@ -6593,10 +6593,12 @@ class V8_EXPORT HeapCodeStatistics {
HeapCodeStatistics();
size_t code_and_metadata_size() { return code_and_metadata_size_; }
size_t bytecode_and_metadata_size() { return bytecode_and_metadata_size_; }
size_t external_script_source_size() { return external_script_source_size_; }
private:
size_t code_and_metadata_size_;
size_t bytecode_and_metadata_size_;
size_t external_script_source_size_;
friend class Isolate;
};
......
......@@ -6026,7 +6026,9 @@ HeapObjectStatistics::HeapObjectStatistics()
object_size_(0) {}
HeapCodeStatistics::HeapCodeStatistics()
: code_and_metadata_size_(0), bytecode_and_metadata_size_(0) {}
: code_and_metadata_size_(0),
bytecode_and_metadata_size_(0),
external_script_source_size_(0) {}
bool v8::V8::InitializeICU(const char* icu_data_file) {
return i::InitializeICU(icu_data_file);
......@@ -8461,6 +8463,8 @@ bool Isolate::GetHeapCodeAndMetadataStatistics(
code_statistics->code_and_metadata_size_ = isolate->code_and_metadata_size();
code_statistics->bytecode_and_metadata_size_ =
isolate->bytecode_and_metadata_size();
code_statistics->external_script_source_size_ =
isolate->external_script_source_size();
return true;
}
......
......@@ -11,32 +11,41 @@ namespace internal {
// Record code statisitcs.
void CodeStatistics::RecordCodeAndMetadataStatistics(HeapObject* object,
Isolate* isolate) {
if (!object->IsAbstractCode()) {
return;
}
// Record code+metadata statisitcs.
AbstractCode* abstract_code = AbstractCode::cast(object);
int size = abstract_code->SizeIncludingMetadata();
if (abstract_code->IsCode()) {
size += isolate->code_and_metadata_size();
isolate->set_code_and_metadata_size(size);
} else {
size += isolate->bytecode_and_metadata_size();
isolate->set_bytecode_and_metadata_size(size);
}
if (object->IsScript()) {
Script* script = Script::cast(object);
// Log the size of external source code.
Object* source = script->source();
if (source->IsExternalString()) {
ExternalString* external_source_string = ExternalString::cast(source);
int size = isolate->external_script_source_size();
size += external_source_string->ExternalPayloadSize();
isolate->set_external_script_source_size(size);
}
} else if (object->IsAbstractCode()) {
// Record code+metadata statisitcs.
AbstractCode* abstract_code = AbstractCode::cast(object);
int size = abstract_code->SizeIncludingMetadata();
if (abstract_code->IsCode()) {
size += isolate->code_and_metadata_size();
isolate->set_code_and_metadata_size(size);
} else {
size += isolate->bytecode_and_metadata_size();
isolate->set_bytecode_and_metadata_size(size);
}
#ifdef DEBUG
// Record code kind and code comment statistics.
isolate->code_kind_statistics()[abstract_code->kind()] +=
abstract_code->Size();
CodeStatistics::CollectCodeCommentStatistics(object, isolate);
// Record code kind and code comment statistics.
isolate->code_kind_statistics()[abstract_code->kind()] +=
abstract_code->Size();
CodeStatistics::CollectCodeCommentStatistics(object, isolate);
#endif
}
}
void CodeStatistics::ResetCodeAndMetadataStatistics(Isolate* isolate) {
isolate->set_code_and_metadata_size(0);
isolate->set_bytecode_and_metadata_size(0);
isolate->set_external_script_source_size(0);
#ifdef DEBUG
ResetCodeStatistics(isolate);
#endif
......
......@@ -3485,6 +3485,7 @@ bool Heap::InvokeNearHeapLimitCallback() {
}
void Heap::CollectCodeStatistics() {
TRACE_EVENT0("v8", "Heap::CollectCodeStatistics");
CodeStatistics::ResetCodeAndMetadataStatistics(isolate());
// We do not look for code in new space, or map space. If code
// somehow ends up in those spaces, we would miss it here.
......
......@@ -644,10 +644,7 @@ void ObjectStatsCollectorImpl::RecordVirtualScriptDetails(Script* script) {
// The contents of external strings aren't on the heap, so we have to record
// them manually.
ExternalString* external_source_string = ExternalString::cast(source);
size_t length_multiplier = external_source_string->IsTwoByteRepresentation()
? kShortSize
: kCharSize;
size_t off_heap_size = external_source_string->length() * length_multiplier;
size_t off_heap_size = external_source_string->ExternalPayloadSize();
size_t on_heap_size = external_source_string->Size();
RecordVirtualObjectStats(script, external_source_string,
ObjectStats::SCRIPT_SOURCE_EXTERNAL_TYPE,
......
......@@ -430,6 +430,7 @@ typedef std::vector<HeapObject*> DebugObjectCache;
V(const v8::StartupData*, snapshot_blob, nullptr) \
V(int, code_and_metadata_size, 0) \
V(int, bytecode_and_metadata_size, 0) \
V(int, external_script_source_size, 0) \
/* true if being profiled. Causes collection of extra compile info. */ \
V(bool, is_profiling, false) \
/* true if a trace is being formatted through Error.prepareStackTrace. */ \
......
......@@ -12089,6 +12089,11 @@ void SeqTwoByteString::clear_padding() {
SizeFor(length()) - data_size);
}
int ExternalString::ExternalPayloadSize() const {
int length_multiplier = IsTwoByteRepresentation() ? kShortSize : kCharSize;
return length() * length_multiplier;
}
uint32_t StringHasher::MakeArrayIndexHash(uint32_t value, int length) {
// For array indexes mix the length into the hash as an array index could
// be zero.
......
......@@ -529,7 +529,7 @@ HeapObject* ThinString::unchecked_actual() const {
return reinterpret_cast<HeapObject*>(READ_FIELD(this, kActualOffset));
}
bool ExternalString::is_short() {
bool ExternalString::is_short() const {
InstanceType type = map()->instance_type();
return (type & kShortExternalStringMask) == kShortExternalStringTag;
}
......
......@@ -717,7 +717,9 @@ class ExternalString : public String {
static const int kSize = kResourceDataOffset + kPointerSize;
// Return whether external string is short (data pointer is not cached).
inline bool is_short();
inline bool is_short() const;
// Size in bytes of the external payload.
int ExternalPayloadSize() const;
// Used in the serializer/deserializer.
inline Address resource_as_address();
......
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