Hi, ben:

>  That code snippet is from CodeStubAssembler::CheckForCapacityGrow(), 
right?

 Yes.

>  V8 at that point knows if it's generating machine code for holey or
non-holey objects. It doesn't have to generate a runtime "is holey?"
type check because it already knows and can specialize right away.

How did v8 know it is holey or not if we don't have this runtime check? 
Thanks.



在2024年9月3日星期二 UTC+8 04:05:39<[email protected]> 写道:

> On Mon, Sep 2, 2024 at 5:17 AM 18楼梦想改造家 <[email protected]> wrote:
> >
> > Hi:
> >
> > I try to read/understand some code in v8 csa sub-system, like this:
> >
> > ``` c++
> > DebugBreak(); // [+] @a
> > if (IsHoleyElementsKind(kind)) { // [+] if statement
> > condition = UintPtrGreaterThanOrEqual(key, length);
> > } else {
> > DebugBreak(); // [+] @b
> > // We don't support growing here unless the value is being appended.
> > condition = WordEqual(key, length);
> > }
> > Branch(condition, &grow_case, &no_grow_case); // [+] Branch statement
> > ```
> > I inserted two breakpoints at points A and B. I originally thought that 
> between these two breakpoints, the code corresponding to 
> |IsHoleyElementsKind(kind)| would be generated to check |kind|. However, it 
> was not the case. There is no other code between the two |DebugBreak| 
> instructions.
> >
> > ``` c++
> > 00007ff6`97326605 cc int 3
> > 00007ff6`97326606 cc int 3
> > 00007ff6`97326607 4d8be0 mov r12,r8
> > ```
> >
> > This means that my assumption was obviously wrong. It seems that I 
> confused the difference between the if keyword and the Branch keyword. So, 
> I came up with the following hypothesis:
> >
> > If we want to achieve an effect similar to if in CSA, we need to use 
> keywords like Branch.
> > What is the role of if in CSA? I suspect that it is handled by 
> mksnapshot to generate different backup codes for different kind. Suppose 
> there are five kinds in total, then five similar pieces of code would be 
> generated.
> >
> > Please tell me if my assumption is correct. If not, what is the 
> difference between if and Branch in CSA?
> >
> > If my assumption is correct, it seems that the kind should only be 
> determined at runtime, so how does V8 know which piece of code to use?
> >
> > Thank you.
>
> To add to Nico's reply -
>
> That code snippet is from CodeStubAssembler::CheckForCapacityGrow(), right?
>
> V8 at that point knows if it's generating machine code for holey or
> non-holey objects. It doesn't have to generate a runtime "is holey?"
> type check because it already knows and can specialize right away.
>

-- 
-- 
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- 
You received this message because you are subscribed to the Google Groups 
"v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-dev/05170fdd-b888-4a12-898d-4c63610f91e6n%40googlegroups.com.

Reply via email to