Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: runtime/vm/heap_trace_test.cc

Issue 11428067: Merge the Merlin heap tracing to top-of-trunk. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: add yet another missing file Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2012 Google Inc. All Rights Reserved.
2 // Author: nricci@google.com (Nathan Ricci)
3 //
4 #include <sstream>
5 #include <iostream>
6 #include <string>
7 #include "vm/growable_array.h"
8 #include "vm/heap_trace.h"
9 #include "vm/unit_test.h"
10 #include "vm/heap.h"
11 #include "vm/dart_api_impl.h"
12
13
14 namespace dart {
15
16 static std::stringstream* the_stream;
17
18 static void* OpenTraceFile(const char* name) {
19 return reinterpret_cast<void*>(the_stream);
20 }
21
22
23 static void WriteToTraceFile(const void* buffer,
24 intptr_t num_bytes,
25 void* stream) {
26 std::stringstream* s_stream = (std::stringstream*)stream;
27 s_stream->write(reinterpret_cast<const char*>(buffer), num_bytes);
28 }
29
30
31 static void CloseTraceFile(void *stream) {
32 }
33
34
35 bool DoesAllocationRecordExist(uword addr, std::string trace_string) {
36 const char* raw_trace = trace_string.c_str();
37 for (unsigned int i = 0; i < trace_string.length(); i++) {
38 if (raw_trace[i] == 'A' && i + 4 < trace_string.length()) {
39 const uword candidate_address =
40 *(reinterpret_cast<const uword*>(raw_trace+i+1));
41 if (candidate_address == addr) {
42 return true;
43 }
44 }
45 }
46
47 return false;
48 }
49
50
51 bool DoesSweepRecordExist(uword addr, std::string trace_string) {
52 const char* raw_trace = trace_string.c_str();
53 for (unsigned int i = 0; i < trace_string.length(); i++) {
54 if (raw_trace[i] == 'S' && i + 4 < trace_string.length()) {
55 const uword candidate_address =
56 *(reinterpret_cast<const uword*>(raw_trace+i+1));
57 if (candidate_address == addr) {
58 return true;
59 }
60 }
61 }
62 return false;
63 }
64
65
66 TEST_CASE(GCTraceAllocate) {
67 const int kArrayLen = 5;
68 the_stream = new std::stringstream();
69 HeapTrace::InitTracing(OpenTraceFile
70 , WriteToTraceFile
71 , CloseTraceFile
72 , "test_prefix");
73
74 Isolate* isolate = Isolate::Current();
75 isolate->heap()->trace()->InitializeIsolateTracing(isolate);
76
77 RawArray* raw_arr = Array::New(kArrayLen);
78 uword addr = RawObject::ToAddr(raw_arr);
79
80
81 ASSERT(DoesAllocationRecordExist(addr, the_stream->str()));
82 delete the_stream;
83 }
84
85 TEST_CASE(GCTraceSweep) {
86 the_stream = new std::stringstream();
87 const int kArrayLen = 5;
88
89 HeapTrace::InitTracing(OpenTraceFile,
90 WriteToTraceFile,
91 CloseTraceFile,
92 "test_prefix");
93
94
95 Isolate* isolate = Isolate::Current();
96 isolate->heap()->trace()->InitializeIsolateTracing(isolate);
97
98 RawArray* raw_arr = Array::New(kArrayLen, Heap::kOld);
99 uword addr = RawObject::ToAddr(raw_arr);
100
101 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
102 DoesSweepRecordExist(addr, the_stream->str());
103 delete the_stream;
104 }
105
106
107 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698