Re: [v8-users] How to dump jit code and its corresponding bytecode.

2017-06-02 Thread Jakob Kummerow
Look at the existing flags FLAG_print_opt_code and FLAG_print_bytecode,
their implementations should help you figure out how to do this.

On Fri, Jun 2, 2017 at 8:07 AM, Yuan Pinghai  wrote:

> I want to dump each piece of dynamically generated code. Meanwhile, if its
> corresponding bytecode is available, I also dump the bytecode and record
> the starting line number of the script code (i.e. recording the script name
> and the line number). For this purpose, i inserted code snippets in
> functions which would invoke "factory->NewCode". The following code is what
> i inserted into "CodeGenerator::GenerateCode()". However, my code can
> only successfully dump jit'ed code, but cannot dump bytecodes and record
> the script information. How can I solve this problem? Thanks!
>
> Bye the way, i am working on Version 6.0.99, the latest commit is
> 71c1795aea7573672dd264568357c0f49afc7321.
>
> --- a/src/compiler/code-generator.cc
> +++ b/src/compiler/code-generator.cc
> @@ -256,7 +256,34 @@ Handle CodeGenerator::GenerateCode() {
>if (info->ShouldEnsureSpaceForLazyDeopt()) {
>  Deoptimizer::EnsureRelocSpaceForLazyDeoptimization(result);
>}
> -
> +   //dump_jit_code(code, info);
> +
> +   byte* nvstart = code->instruction_start();
> +   //code->instruction_size();
> +   int nvlen = code->body_size();
> +
> +   int type = 0;
> +   if (code->is_crankshafted())
> +   type += (1 << 0);
> +   if (code->is_turbofanned())
> +   type += (1 << 1);
> +
> +   printf("%p, %i, %i \n", nvstart, nvlen, type);
> +
> +   std::unique_ptr debug_name = info->GetDebugName();
> +   OFStream os(stdout);
> +   os << debug_name.get()<< std::endl;
> +
> +   if (info->has_bytecode_array()){
> +   Handle  bytecodes = info->bytecode_array();
> +   bytecodes->Print(os);
> +   }
> +
> +   

[v8-users] How to dump jit code and its corresponding bytecode.

2017-06-02 Thread Yuan Pinghai
I want to dump each piece of dynamically generated code. Meanwhile, if its 
corresponding bytecode is available, I also dump the bytecode and record 
the starting line number of the script code (i.e. recording the script name 
and the line number). For this purpose, i inserted code snippets in 
functions which would invoke "factory->NewCode". The following code is what 
i inserted into "CodeGenerator::GenerateCode()". However, my code can only 
successfully dump jit'ed code, but cannot dump bytecodes and record the 
script information. How can I solve this problem? Thanks!

Bye the way, i am working on Version 6.0.99, the latest commit is 
71c1795aea7573672dd264568357c0f49afc7321.

--- a/src/compiler/code-generator.cc
+++ b/src/compiler/code-generator.cc
@@ -256,7 +256,34 @@ Handle CodeGenerator::GenerateCode() {
   if (info->ShouldEnsureSpaceForLazyDeopt()) {
 Deoptimizer::EnsureRelocSpaceForLazyDeoptimization(result);
   }
-
+   //dump_jit_code(code, info);
+
+   byte* nvstart = code->instruction_start();
+   //code->instruction_size();
+   int nvlen = code->body_size();
+
+   int type = 0;
+   if (code->is_crankshafted())
+   type += (1 << 0);
+   if (code->is_turbofanned())
+   type += (1 << 1);
+
+   printf("%p, %i, %i \n", nvstart, nvlen, type);
+
+   std::unique_ptr debug_name = info->GetDebugName();
+   OFStream os(stdout);
+   os << debug_name.get()<< std::endl;
+
+   if (info->has_bytecode_array()){
+   Handle  bytecodes = info->bytecode_array();
+   bytecodes->Print(os);
+   }
+   
+