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

Side by Side Diff: tools/parser-shell.cc

Issue 2101413002: Provide a convenience array buffer allocator (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 4 years, 5 months 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
« no previous file with comments | « test/unittests/test-utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 27 matching lines...) Expand all
38 #include "src/compiler.h" 38 #include "src/compiler.h"
39 #include "src/parsing/scanner-character-streams.h" 39 #include "src/parsing/scanner-character-streams.h"
40 #include "src/parsing/parser.h" 40 #include "src/parsing/parser.h"
41 #include "src/parsing/preparse-data-format.h" 41 #include "src/parsing/preparse-data-format.h"
42 #include "src/parsing/preparse-data.h" 42 #include "src/parsing/preparse-data.h"
43 #include "src/parsing/preparser.h" 43 #include "src/parsing/preparser.h"
44 #include "tools/shell-utils.h" 44 #include "tools/shell-utils.h"
45 45
46 using namespace v8::internal; 46 using namespace v8::internal;
47 47
48 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
49 public:
50 virtual void* Allocate(size_t length) {
51 void* data = AllocateUninitialized(length);
52 return data == NULL ? data : memset(data, 0, length);
53 }
54 virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
55 virtual void Free(void* data, size_t) { free(data); }
56 };
57
58 class StringResource8 : public v8::String::ExternalOneByteStringResource { 48 class StringResource8 : public v8::String::ExternalOneByteStringResource {
59 public: 49 public:
60 StringResource8(const char* data, int length) 50 StringResource8(const char* data, int length)
61 : data_(data), length_(length) { } 51 : data_(data), length_(length) { }
62 virtual size_t length() const { return length_; } 52 virtual size_t length() const { return length_; }
63 virtual const char* data() const { return data_; } 53 virtual const char* data() const { return data_; }
64 54
65 private: 55 private:
66 const char* data_; 56 const char* data_;
67 int length_; 57 int length_;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 encoding = UTF16; 151 encoding = UTF16;
162 } else if (strncmp(argv[i], "--benchmark=", 12) == 0) { 152 } else if (strncmp(argv[i], "--benchmark=", 12) == 0) {
163 benchmark = std::string(argv[i]).substr(12); 153 benchmark = std::string(argv[i]).substr(12);
164 } else if (strncmp(argv[i], "--repeat=", 9) == 0) { 154 } else if (strncmp(argv[i], "--repeat=", 9) == 0) {
165 std::string repeat_str = std::string(argv[i]).substr(9); 155 std::string repeat_str = std::string(argv[i]).substr(9);
166 repeat = atoi(repeat_str.c_str()); 156 repeat = atoi(repeat_str.c_str());
167 } else if (i > 0 && argv[i][0] != '-') { 157 } else if (i > 0 && argv[i][0] != '-') {
168 fnames.push_back(std::string(argv[i])); 158 fnames.push_back(std::string(argv[i]));
169 } 159 }
170 } 160 }
171 ArrayBufferAllocator array_buffer_allocator;
172 v8::Isolate::CreateParams create_params; 161 v8::Isolate::CreateParams create_params;
173 create_params.array_buffer_allocator = &array_buffer_allocator; 162 create_params.array_buffer_allocator =
163 v8::ArrayBuffer::Allocator::NewDefaultAllocator();
174 v8::Isolate* isolate = v8::Isolate::New(create_params); 164 v8::Isolate* isolate = v8::Isolate::New(create_params);
175 { 165 {
176 v8::Isolate::Scope isolate_scope(isolate); 166 v8::Isolate::Scope isolate_scope(isolate);
177 v8::HandleScope handle_scope(isolate); 167 v8::HandleScope handle_scope(isolate);
178 v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate); 168 v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
179 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); 169 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global);
180 DCHECK(!context.IsEmpty()); 170 DCHECK(!context.IsEmpty());
181 { 171 {
182 v8::Context::Scope scope(context); 172 v8::Context::Scope scope(context);
183 double first_parse_total = 0; 173 double first_parse_total = 0;
184 double second_parse_total = 0; 174 double second_parse_total = 0;
185 for (size_t i = 0; i < fnames.size(); i++) { 175 for (size_t i = 0; i < fnames.size(); i++) {
186 std::pair<v8::base::TimeDelta, v8::base::TimeDelta> time = 176 std::pair<v8::base::TimeDelta, v8::base::TimeDelta> time =
187 RunBaselineParser(fnames[i].c_str(), encoding, repeat, isolate, 177 RunBaselineParser(fnames[i].c_str(), encoding, repeat, isolate,
188 context); 178 context);
189 first_parse_total += time.first.InMillisecondsF(); 179 first_parse_total += time.first.InMillisecondsF();
190 second_parse_total += time.second.InMillisecondsF(); 180 second_parse_total += time.second.InMillisecondsF();
191 } 181 }
192 if (benchmark.empty()) benchmark = "Baseline"; 182 if (benchmark.empty()) benchmark = "Baseline";
193 printf("%s(FirstParseRunTime): %.f ms\n", benchmark.c_str(), 183 printf("%s(FirstParseRunTime): %.f ms\n", benchmark.c_str(),
194 first_parse_total); 184 first_parse_total);
195 printf("%s(SecondParseRunTime): %.f ms\n", benchmark.c_str(), 185 printf("%s(SecondParseRunTime): %.f ms\n", benchmark.c_str(),
196 second_parse_total); 186 second_parse_total);
197 } 187 }
198 } 188 }
199 v8::V8::Dispose(); 189 v8::V8::Dispose();
200 v8::V8::ShutdownPlatform(); 190 v8::V8::ShutdownPlatform();
201 delete platform; 191 delete platform;
192 delete create_params.array_buffer_allocator;
202 return 0; 193 return 0;
203 } 194 }
OLDNEW
« no previous file with comments | « test/unittests/test-utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698