Bug 131205

Summary: LLInt interpreter code should be generated as part of one function
Product: WebKit Reporter: Michael Saboff <msaboff>
Component: JavaScriptCoreAssignee: Michael Saboff <msaboff>
Status: RESOLVED FIXED    
Severity: Normal CC: bunhere, commit-queue, fpizlo, ggaren, gyuyoung.kim, jbriance, mark.lam, mhahnenberg, oliver, rakuco, sergio
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Bug Depends on: 131612, 132738    
Bug Blocks: 129178    
Attachments:
Description Flags
Compiles and runs X86 (32 & 64)
none
Updated patch
none
Patch
none
Patch addressing issues raised in review
mark.lam: review+
Generated LLIntAssembly.h before this change
none
Generated LLIntAssembly.h after this change none

Description Michael Saboff 2014-04-03 19:23:39 PDT
Currently each LLInt opcode as well as the various relate LLInt helpers are generated as separate global functions.  Instead, all of the opcode functions and related helpers should be in one global function.  This would help with stack traces and eliminate issues caused by the linker relocating the functions.  There should be one entry point, say _llint_entry.
Comment 1 Michael Saboff 2014-04-03 19:31:49 PDT
Created attachment 228574 [details]
Compiles and runs X86 (32 & 64)

Builds and runs on X86 (32 & 64).

ToDo:
 * Add ARM support to LowLevelInterpreter.asm possibly with offline assembler support.
 * Change opcode labels to true locals.  lldb still thinks these are entry points even though they are exported.
 * Add more safeguards to expressions involving labels to offline assembler.
Comment 2 Michael Saboff 2014-04-04 20:04:33 PDT
Created attachment 228649 [details]
Updated patch

Builds and runs on X86 (32 & 64), ARMv7 and ARM64.

ToDo:
 * Add more safeguards to expressions involving labels to offline assembler.
 * Full testing of ARM variants
 * Windows changes & build
 * C Loop
 * Makefile changes for non-Apple platforms
Comment 3 Michael Saboff 2014-04-08 14:43:06 PDT
Created attachment 228891 [details]
Patch

Builds and tested on Mac 32 & 64, iOS 32 & 64, C Loop.  Builds on Windows 32 (with LLInt).

Speculative work for Arm Traditional.  Specifically does not run on MIPS and SH4.  Contact me for pointers how to get those platforms working again.
Comment 4 Mark Lam 2014-04-08 17:21:42 PDT
Comment on attachment 228891 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=228891&action=review

> Source/JavaScriptCore/llint/LLIntData.h:131
> +#if 1

Why #if 1?  Is this superfluous?

> Source/JavaScriptCore/llint/LowLevelInterpreter.h:52
> +#if 0

Why #if 0?  Why not just remove this section of code?  Do you anticipate it being used again in the near future?
Comment 5 Michael Saboff 2014-04-08 17:23:50 PDT
(In reply to comment #4)
> (From update of attachment 228891 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=228891&action=review
> 
> > Source/JavaScriptCore/llint/LLIntData.h:131
> > +#if 1
> 
> Why #if 1?  Is this superfluous?
> 
> > Source/JavaScriptCore/llint/LowLevelInterpreter.h:52
> > +#if 0
> 
> Why #if 0?  Why not just remove this section of code?  Do you anticipate it being used again in the near future?

I'll remove these.  They are holdovers from developing the patch.
Comment 6 Mark Lam 2014-04-09 15:19:35 PDT
Comment on attachment 228891 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=228891&action=review

> Source/JavaScriptCore/ChangeLog:40
> +        well as including file from other than the local director via a newly added -I

/file/files/
/director/directory/

> Source/JavaScriptCore/ChangeLog:43
> +        source.  This is used both choosing the correct macro for external references as

/both choosing/both for choosing/

> Source/JavaScriptCore/ChangeLog:45
> +        of the masm only .sym file to be written once at the end of online assembling.

/online assembling/offline assembly/

> Source/JavaScriptCore/assembler/MacroAssemblerCodeRef.h:297
> -    static MacroAssemblerCodePtr createLLIntCodePtr(LLIntCode codeId)
> +    static MacroAssemblerCodePtr createLLIntCodeRefForHelper(unsigned id)

Should this be named “createLLIntCodePtrForHelper" instead because you’re returning a MacroAssemblerCodePtr (which is distinct from the createLLIntCodeRefForHelper below which actually returns a MacroAssemblerCodeRef)?

> Source/JavaScriptCore/llint/LLIntData.h:98
> +ALWAYS_INLINE void* getHelperCodePtr(unsigned id)

Michael, you’ve mentioned offline that you plan to change some #defines to enums.  I presume you were referring to the helper id here.  Please make it so.

> Source/JavaScriptCore/llint/LLIntData.h:108
> +ALWAYS_INLINE void(*getHelperFunctionPtr(unsigned id))()

This is hard to read.  You should use a typedef, and there is already one that you can use.  See LLIntCode in llint/LLIntData.h.  Hence, you can change this to:

ALWAYS_INLINE LLIntCode getHelperFunctionPtr(unsigned id)

Feel free to rename LLIntCode to a better name is appropriate.

> Source/JavaScriptCore/llint/LLIntData.h:110
> +    return reinterpret_cast<void (*)()>(getHelperCodePtr(id));

Ditto.  Change to:
    return reinterpret_cast<LLIntCode>(getHelperCodePtr(id));

> Source/JavaScriptCore/llint/LowLevelInterpreter.asm:752
> +include InitBytecodes

nit: I’d prefer to indent this include directive, but other folks may (or may not) have a different opinion.  Just thought I’d mention it for your consideration.

> Source/JavaScriptCore/offlineasm/asm.rb:193
> +        end            

Looks like this “end” needs to be indented.
Comment 7 Michael Saboff 2014-04-10 12:05:47 PDT
Created attachment 229066 [details]
Patch addressing issues raised in review
Comment 8 Michael Saboff 2014-04-10 12:16:50 PDT
Created attachment 229067 [details]
Generated LLIntAssembly.h before this change
Comment 9 Michael Saboff 2014-04-10 12:17:27 PDT
Created attachment 229068 [details]
Generated LLIntAssembly.h after this change
Comment 10 Michael Saboff 2014-04-10 12:18:21 PDT
Per an offline discussion with Mark, I added samples of the generated LLIntAssembly.h files before and after this change.
Comment 11 Mark Lam 2014-04-10 14:58:26 PDT
Comment on attachment 229066 [details]
Patch addressing issues raised in review

View in context: https://bugs.webkit.org/attachment.cgi?id=229066&action=review

r=me with fixes.

> Source/JavaScriptCore/ChangeLog:40
> +        as well as  including files from other than the local directory via a newly

Extra space between "as  including".

> Source/JavaScriptCore/ChangeLog:45
> +        Updated the generationo f the masm only .sym file to be written once at the end

/generationo f/generation of/.

> Source/JavaScriptCore/ChangeLog:46
> +        of online assembling.

/online assembling/offline assembly/.

> Source/JavaScriptCore/llint/LLIntData.h:38
> +const int opcodeMapSize = NUMBER_OF_BYTECODE_IDS + NUMBER_OF_CLOOP_BYTECODE_HELPER_IDS + NUMBER_OF_BYTECODE_HELPER_IDS;

This looks identical to the definition of numOpcodeIDs.  I think once upon a time, these 2 values are different, but now they are redundant.  Let's get rid of opcodeMapSize and just use numOpcodeIDs everywhere instead.

> Source/JavaScriptCore/llint/LLIntData.h:41
> +const int opcodeMapSize = NUMBER_OF_BYTECODE_IDS + NUMBER_OF_BYTECODE_HELPER_IDS;

Ditto.

> Source/JavaScriptCore/llint/LLIntData.h:64
> +    friend void* getCodePtr(unsigned);
> +    friend void* getHelperCodePtr(unsigned);

I think these 2 are now obsolete and not referenced anywhere.  Please remove.

> Source/JavaScriptCore/llint/LLIntData.h:118
>  ALWAYS_INLINE void* getCodePtr(JSC::EncodedJSValue glueHelper())

I presume this is still needed for "LLInt::getCodePtr(getHostCallReturnValue))" or something.  Please confirm that it is still needed.  If not, please remove.

> Source/JavaScriptCore/llint/LowLevelInterpreter.h:50
>  #endif // !ENABLE(LLINT_C_LOOP)

/!ENABLE(LLINT_C_LOOP)/ENABLE(LLINT_C_LOOP)/ since there's no longer a !ENABLE(LLINT_C_LOOP) case.
Comment 12 Michael Saboff 2014-04-10 15:33:13 PDT
(In reply to comment #11)
> (From update of attachment 229066 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=229066&action=review
> 
> r=me with fixes.
> 
> > Source/JavaScriptCore/ChangeLog:40
> > +        as well as  including files from other than the local directory via a newly
> 
> Extra space between "as  including".
> 
> > Source/JavaScriptCore/ChangeLog:45
> > +        Updated the generationo f the masm only .sym file to be written once at the end
> 
> /generationo f/generation of/.
> 
> > Source/JavaScriptCore/ChangeLog:46
> > +        of online assembling.
> 
> /online assembling/offline assembly/.
> 
> > Source/JavaScriptCore/llint/LLIntData.h:38
> > +const int opcodeMapSize = NUMBER_OF_BYTECODE_IDS + NUMBER_OF_CLOOP_BYTECODE_HELPER_IDS + NUMBER_OF_BYTECODE_HELPER_IDS;
> 
> This looks identical to the definition of numOpcodeIDs.  I think once upon a time, these 2 values are different, but now they are redundant.  Let's get rid of opcodeMapSize and just use numOpcodeIDs everywhere instead.
> 
> > Source/JavaScriptCore/llint/LLIntData.h:41
> > +const int opcodeMapSize = NUMBER_OF_BYTECODE_IDS + NUMBER_OF_BYTECODE_HELPER_IDS;
> 
> Ditto.
> 
> > Source/JavaScriptCore/llint/LLIntData.h:64
> > +    friend void* getCodePtr(unsigned);
> > +    friend void* getHelperCodePtr(unsigned);
> 
> I think these 2 are now obsolete and not referenced anywhere.  Please remove.
> 
> 
> > Source/JavaScriptCore/llint/LowLevelInterpreter.h:50
> >  #endif // !ENABLE(LLINT_C_LOOP)
> 
> /!ENABLE(LLINT_C_LOOP)/ENABLE(LLINT_C_LOOP)/ since there's no longer a !ENABLE(LLINT_C_LOOP) case.

Made the suggested changes except:

> > Source/JavaScriptCore/llint/LLIntData.h:118
> >  ALWAYS_INLINE void* getCodePtr(JSC::EncodedJSValue glueHelper())
> 
> I presume this is still needed for "LLInt::getCodePtr(getHostCallReturnValue))" or something.  Please confirm that it is still needed.  If not, please remove.

Yes, this is why this is needed.
Comment 13 Michael Saboff 2014-04-10 15:34:32 PDT
Committed r167094: <http://trac.webkit.org/changeset/167094>