33 #ifdef COMPRESS_STARTUP_DATA_BZ2
34 #error Using compressed startup data is not supported for this sample
51 virtual const string& Path() = 0;
52 virtual const string& Referrer() = 0;
53 virtual const string& Host() = 0;
54 virtual const string& UserAgent() = 0;
67 virtual bool Initialize(map<string, string>* options,
68 map<string, string>* output) = 0;
73 static void Log(
const char* event);
85 : isolate_(isolate), script_(script) { }
88 virtual bool Initialize(map<string, string>* opts,
89 map<string, string>* output);
99 bool InstallMaps(map<string, string>* opts, map<string, string>* output);
130 Isolate* GetIsolate() {
return isolate_; }
147 if (args.
Length() < 1)
return;
157 map<string, string>* output) {
164 global->
Set(String::NewFromUtf8(GetIsolate(),
"log"),
165 FunctionTemplate::New(GetIsolate(), LogCallback));
173 context_.Reset(GetIsolate(), context);
180 if (!InstallMaps(opts, output))
184 if (!ExecuteScript(script_))
189 Handle<String> process_name = String::NewFromUtf8(GetIsolate(),
"Process");
201 process_.Reset(GetIsolate(), process_fun);
208 bool JsHttpRequestProcessor::ExecuteScript(
Handle<String> script) {
217 if (compiled_script.
IsEmpty()) {
237 bool JsHttpRequestProcessor::InstallMaps(map<string, string>* opts,
238 map<string, string>* output) {
248 context->
Global()->Set(String::NewFromUtf8(GetIsolate(),
"options"),
252 context->
Global()->Set(String::NewFromUtf8(GetIsolate(),
"output"),
318 if (map_template_.IsEmpty()) {
320 map_template_.Reset(GetIsolate(), raw_template);
333 result->SetInternalField(0, map_ptr);
339 return handle_scope.Escape(result);
345 map<string, string>* JsHttpRequestProcessor::UnwrapMap(
Handle<Object> obj) {
347 void* ptr = field->
Value();
348 return static_cast<map<string, string>*
>(ptr);
356 return string(*utf8_value);
363 map<string, string>* obj = UnwrapMap(info.
Holder());
369 map<string, string>::iterator iter = obj->find(key);
372 if (iter == obj->end())
return;
375 const string& value = (*iter).second;
377 info.
GetIsolate(), value.c_str(), String::kNormalString,
378 static_cast<int>(value.length())));
386 map<string, string>* obj = UnwrapMap(info.
Holder());
409 return handle_scope.Escape(result);
427 if (request_template_.IsEmpty()) {
429 request_template_.Reset(GetIsolate(), raw_template);
442 result->SetInternalField(0, request_ptr);
448 return handle_scope.Escape(result);
458 void* ptr = field->
Value();
469 const string& path = request->
Path();
473 info.
GetIsolate(), path.c_str(), String::kNormalString,
474 static_cast<int>(path.length())));
478 void JsHttpRequestProcessor::GetReferrer(
482 const string& path = request->
Referrer();
484 info.
GetIsolate(), path.c_str(), String::kNormalString,
485 static_cast<int>(path.length())));
492 const string& path = request->
Host();
494 info.
GetIsolate(), path.c_str(), String::kNormalString,
495 static_cast<int>(path.length())));
499 void JsHttpRequestProcessor::GetUserAgent(
503 const string& path = request->
UserAgent();
505 info.
GetIsolate(), path.c_str(), String::kNormalString,
506 static_cast<int>(path.length())));
519 String::NewFromUtf8(isolate,
"path", String::kInternalizedString),
522 String::NewFromUtf8(isolate,
"referrer", String::kInternalizedString),
525 String::NewFromUtf8(isolate,
"host", String::kInternalizedString),
528 String::NewFromUtf8(isolate,
"userAgent", String::kInternalizedString),
532 return handle_scope.Escape(result);
540 printf(
"Logged: %s\n", event);
550 const string& referrer,
552 const string& user_agent);
553 virtual const string&
Path() {
return path_; }
554 virtual const string&
Referrer() {
return referrer_; }
555 virtual const string&
Host() {
return host_; }
556 virtual const string&
UserAgent() {
return user_agent_; }
566 const string& referrer,
568 const string& user_agent)
572 user_agent_(user_agent) { }
577 map<string, string>& options,
579 for (
int i = 1; i < argc; i++) {
580 string arg = argv[i];
581 size_t index = arg.find(
'=', 0);
582 if (index == string::npos) {
585 string key = arg.substr(0, index);
586 string value = arg.substr(index+1);
587 options[key] = value;
595 FILE* file = fopen(name.c_str(),
"rb");
598 fseek(file, 0, SEEK_END);
599 int size = ftell(file);
602 char* chars =
new char[size + 1];
604 for (
int i = 0; i <
size;) {
605 int read =
static_cast<int>(fread(&chars[i], 1, size - i, file));
610 String::NewFromUtf8(isolate, chars, String::kNormalString, size);
629 for (
int i = 0; i < count; i++) {
630 if (!processor->
Process(&reqs[i]))
638 for (map<string, string>::iterator i = m->begin(); i != m->end(); i++) {
639 pair<string, string> entry = *i;
640 printf(
"%s: %s\n", entry.first.c_str(), entry.second.c_str());
645 int main(
int argc,
char* argv[]) {
647 map<string, string> options;
651 fprintf(stderr,
"No script was specified.\n");
654 Isolate* isolate = Isolate::GetCurrent();
658 fprintf(stderr,
"Error reading '%s'.\n", file.c_str());
662 map<string, string> output;
663 if (!processor.
Initialize(&options, &output)) {
664 fprintf(stderr,
"Error initializing processor.\n");
void SetAccessor(Handle< String > name, AccessorGetterCallback getter, AccessorSetterCallback setter=0, Handle< Value > data=Handle< Value >(), AccessControl settings=DEFAULT, PropertyAttribute attribute=None, Handle< AccessorSignature > signature=Handle< AccessorSignature >())
virtual bool Process(HttpRequest *req)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
static V8_INLINE Local< T > New(Isolate *isolate, Handle< T > that)
Local< Value > Call(Handle< Value > recv, int argc, Handle< Value > argv[])
bool ProcessEntries(HttpRequestProcessor *processor, int count, StringHttpRequest *reqs)
Local< Value > Exception() const
virtual const string & Referrer()
V8_INLINE Isolate * GetIsolate() const
virtual ~HttpRequestProcessor()
Local< Object > NewInstance()
virtual const string & Path()=0
V8_INLINE int Length() const
virtual ~JsHttpRequestProcessor()
V8_INLINE Local< Object > Holder() const
string ObjectToString(Local< Value > value)
Handle< String > ReadFile(Isolate *isolate, const string &name)
V8_INLINE Local< Value > GetInternalField(int index)
void Set(Handle< String > name, Handle< Data > value, PropertyAttribute attributes=None)
virtual const string & UserAgent()=0
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long expose natives in global object expose freeBuffer extension expose gc extension under the specified name expose externalize string extension number of stack frames to capture disable builtin natives files print name of functions for which code is generated use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations always try to OSR functions trace optimize function deoptimization minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions trace debugging JSON request response trace out of bounds accesses to external arrays trace_js_array_abuse automatically set the debug break flag when debugger commands are in the queue abort by crashing maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print statistics of the maximum memory committed for the heap in name
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object size
UniqueSet< Map > * MapSet
virtual const string & Path()
JsHttpRequestProcessor(Isolate *isolate, Handle< String > script)
void SetNamedPropertyHandler(NamedPropertyGetterCallback getter, NamedPropertySetterCallback setter=0, NamedPropertyQueryCallback query=0, NamedPropertyDeleterCallback deleter=0, NamedPropertyEnumeratorCallback enumerator=0, Handle< Value > data=Handle< Value >())
int main(int argc, char *argv[])
virtual bool Process(HttpRequest *req)=0
V8_INLINE Isolate * GetIsolate() const
void SetInternalFieldCount(int value)
void PrintMap(map< string, string > *m)
virtual bool Initialize(map< string, string > *opts, map< string, string > *output)
V8_INLINE ReturnValue< T > GetReturnValue() const
void ParseOptions(int argc, char *argv[], map< string, string > &options, string *file)
static void Log(const char *event)
virtual const string & Referrer()=0
virtual const string & Host()
V8_INLINE bool IsEmpty() const
StringHttpRequest(const string &path, const string &referrer, const string &host, const string &user_agent)
virtual const string & Host()=0
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function info
static bool InitializeICU(const char *icu_data_file=NULL)
StringHttpRequest kSampleRequests[kSampleSize]
virtual const string & UserAgent()