# HG changeset patch
# User Hannes Verschore <hv1989@gmail.com>
# Date 1448912718 -3600
# Node ID 7683aae0caff682c97e21bbe0e6e40c0c958f7eb
# Parent 541a97a551cb7bdd2791e937b3cb2a087b0eab6f
Bug 1227028: TraceLogger - Fix when to keep the payload of a TraceLogger event, r=bbouvier
diff --git a/js/src/jit/Ion.cpp b/js/src/jit/Ion.cpp
a
|
b
|
IonScript::Trace(JSTracer* trc, IonScrip
|
1247 | 1247 | void |
1248 | 1248 | IonScript::Destroy(FreeOp* fop, IonScript* script) |
1249 | 1249 | { |
1250 | 1250 | if (script->pendingBuilder()) |
1251 | 1251 | jit::FinishOffThreadBuilder(nullptr, script->pendingBuilder()); |
1252 | 1252 | |
1253 | 1253 | script->destroyCaches(); |
1254 | 1254 | script->unlinkFromRuntime(fop); |
| 1255 | // Frees the potential event we have set. |
| 1256 | script->traceLoggerScriptEvent_ = TraceLoggerEvent(); |
1255 | 1257 | fop->free_(script); |
1256 | 1258 | } |
1257 | 1259 | |
1258 | 1260 | void |
1259 | 1261 | IonScript::toggleBarriers(bool enabled) |
1260 | 1262 | { |
1261 | 1263 | method()->togglePreBarriers(enabled); |
1262 | 1264 | } |
diff --git a/js/src/vm/TraceLogging.cpp b/js/src/vm/TraceLogging.cpp
a
|
b
|
TraceLoggerThread::extractScriptDetails(
|
344 | 344 | *lineno_len = *colno - *lineno - 1; |
345 | 345 | *colno_len = strlen(*colno); |
346 | 346 | } |
347 | 347 | |
348 | 348 | TraceLoggerEventPayload* |
349 | 349 | TraceLoggerThread::getOrCreateEventPayload(TraceLoggerTextId textId) |
350 | 350 | { |
351 | 351 | TextIdHashMap::AddPtr p = textIdPayloads.lookupForAdd(textId); |
352 | | if (p) |
| 352 | if (p) { |
| 353 | MOZ_ASSERT(p->value()->textId() == textId); // Sanity check. |
353 | 354 | return p->value(); |
| 355 | } |
354 | 356 | |
355 | 357 | TraceLoggerEventPayload* payload = js_new<TraceLoggerEventPayload>(textId, (char*)nullptr); |
356 | 358 | |
357 | 359 | if (!textIdPayloads.add(p, textId, payload)) |
358 | 360 | return nullptr; |
359 | 361 | |
360 | 362 | return payload; |
361 | 363 | } |
362 | 364 | |
363 | 365 | TraceLoggerEventPayload* |
364 | 366 | TraceLoggerThread::getOrCreateEventPayload(const char* text) |
365 | 367 | { |
366 | 368 | PointerHashMap::AddPtr p = pointerMap.lookupForAdd((const void*)text); |
367 | | if (p) |
| 369 | if (p) { |
| 370 | MOZ_ASSERT(p->value()->textId() < nextTextId); // Sanity check. |
368 | 371 | return p->value(); |
| 372 | } |
369 | 373 | |
370 | 374 | size_t len = strlen(text); |
371 | 375 | char* str = js_pod_malloc<char>(len + 1); |
372 | 376 | if (!str) |
373 | 377 | return nullptr; |
374 | 378 | |
375 | 379 | DebugOnly<size_t> ret = JS_snprintf(str, len + 1, "%s", text); |
376 | 380 | MOZ_ASSERT(ret == len); |
… |
… |
TraceLoggerThread::getOrCreateEventPaylo
|
412 | 416 | |
413 | 417 | // Only log scripts when enabled otherwise return the global Scripts textId, |
414 | 418 | // which will get filtered out. |
415 | 419 | MOZ_ASSERT(traceLoggerState); |
416 | 420 | if (!traceLoggerState->isTextIdEnabled(type)) |
417 | 421 | return getOrCreateEventPayload(type); |
418 | 422 | |
419 | 423 | PointerHashMap::AddPtr p = pointerMap.lookupForAdd(ptr); |
420 | | if (p) |
| 424 | if (p) { |
| 425 | MOZ_ASSERT(p->value()->textId() < nextTextId); // Sanity check. |
421 | 426 | return p->value(); |
| 427 | } |
422 | 428 | |
423 | 429 | // Compute the length of the string to create. |
424 | 430 | size_t lenFilename = strlen(filename); |
425 | 431 | size_t lenLineno = 1; |
426 | 432 | for (size_t i = lineno; i /= 10; lenLineno++); |
427 | 433 | size_t lenColno = 1; |
428 | 434 | for (size_t i = colno; i /= 10; lenColno++); |
429 | 435 | |
… |
… |
TraceLoggerThread::log(uint32_t id)
|
561 | 567 | entryStart.time = start; |
562 | 568 | entryStart.textId = TraceLogger_Internal; |
563 | 569 | |
564 | 570 | EventEntry& entryStop = events.pushUninitialized(); |
565 | 571 | entryStop.time = rdtsc() - traceLoggerState->startupTime; |
566 | 572 | entryStop.textId = TraceLogger_Stop; |
567 | 573 | } |
568 | 574 | |
569 | | // Free all TextEvents that have no uses anymore. |
| 575 | // Remove the item in the pointerMap for which the payloads |
| 576 | // have no uses anymore |
| 577 | for (PointerHashMap::Enum e(pointerMap); !e.empty(); e.popFront()) { |
| 578 | if (e.front().value()->uses() != 0) |
| 579 | continue; |
| 580 | |
| 581 | TextIdHashMap::Ptr p = textIdPayloads.lookup(e.front().value()->textId()); |
| 582 | MOZ_ASSERT(p); |
| 583 | textIdPayloads.remove(p); |
| 584 | |
| 585 | e.removeFront(); |
| 586 | } |
| 587 | |
| 588 | // Free all payloads that have no uses anymore. |
570 | 589 | for (TextIdHashMap::Enum e(textIdPayloads); !e.empty(); e.popFront()) { |
571 | 590 | if (e.front().value()->uses() == 0) { |
572 | 591 | js_delete(e.front().value()); |
573 | 592 | e.removeFront(); |
574 | 593 | } |
575 | 594 | } |
576 | 595 | } |
577 | 596 | |
… |
… |
TraceLoggerEvent::TraceLoggerEvent(Trace
|
992 | 1011 | } |
993 | 1012 | } |
994 | 1013 | |
995 | 1014 | TraceLoggerEvent::~TraceLoggerEvent() |
996 | 1015 | { |
997 | 1016 | if (payload_) |
998 | 1017 | payload_->release(); |
999 | 1018 | } |
| 1019 | |
| 1020 | TraceLoggerEvent& |
| 1021 | TraceLoggerEvent::operator=(const TraceLoggerEvent& other) |
| 1022 | { |
| 1023 | if (hasPayload()) |
| 1024 | payload()->release(); |
| 1025 | if (other.hasPayload()) |
| 1026 | other.payload()->use(); |
| 1027 | |
| 1028 | payload_ = other.payload_; |
| 1029 | |
| 1030 | return *this; |
| 1031 | } |
diff --git a/js/src/vm/TraceLogging.h b/js/src/vm/TraceLogging.h
a
|
b
|
class TraceLoggerEvent {
|
105 | 105 | |
106 | 106 | TraceLoggerEventPayload* payload() const { |
107 | 107 | MOZ_ASSERT(hasPayload()); |
108 | 108 | return payload_; |
109 | 109 | } |
110 | 110 | bool hasPayload() const { |
111 | 111 | return !!payload_; |
112 | 112 | } |
| 113 | |
| 114 | TraceLoggerEvent& operator=(const TraceLoggerEvent& other); |
| 115 | TraceLoggerEvent(const TraceLoggerEvent& event) = delete; |
113 | 116 | }; |
114 | 117 | |
115 | 118 | /** |
116 | 119 | * An internal class holding the to-report string information, together with an |
117 | 120 | * unique id and a useCount. Whenever this useCount reaches 0, this event |
118 | 121 | * cannot get started/stopped anymore. Though consumers might still request the |
119 | 122 | * to-report string information. |
120 | 123 | */ |
… |
… |
class TraceLoggerEventPayload {
|
125 | 128 | |
126 | 129 | public: |
127 | 130 | TraceLoggerEventPayload(uint32_t textId, char* string) |
128 | 131 | : textId_(textId), |
129 | 132 | string_(string), |
130 | 133 | uses_(0) |
131 | 134 | { } |
132 | 135 | |
| 136 | ~TraceLoggerEventPayload() { |
| 137 | MOZ_ASSERT(uses_ == 0); |
| 138 | } |
| 139 | |
133 | 140 | uint32_t textId() { |
134 | 141 | return textId_; |
135 | 142 | } |
136 | 143 | const char* string() { |
137 | 144 | return string_.get(); |
138 | 145 | } |
139 | 146 | uint32_t uses() { |
140 | 147 | return uses_; |