[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-graal-dev
Subject:    Re: Identifying bound/free name in a FrameDescriptor
From:       Adam Kovari <kovariadam () gmail ! com>
Date:       2019-02-09 14:32:25
Message-ID: CABrAx89c2bbhGCEAuOhJP0b2aRTmNhWb11P7vgRqsmNdVWZfvQ () mail ! gmail ! com
[Download RAW message or body]

Hi Andreas,

thank you very much for your answer and the example. Yes, I think it
makes sense to use the default value marker for this case.


Thanks,
Adam

št 7. 2. 2019 o 15:55 Andreas Woess <andreas.woess@oracle.com> napísal(a):
> 
> Hi Adam,
> 
> the Frame implementation is (currently) not really designed to have dynamic \
> bindings. As you already know, the FrameDescriptor is shared between multiple Frame \
> instances (invocations), so either none or all of them have a FrameSlot. For an \
> unset or later added FrameSlot, isObject(slot) will return true and getObject(slot) \
> == frameDescriptor.getDefaultValue(). 
> In order to decide if a binding is bound in a particular invocation, I'd suggest to \
> use a marker value or null to mark a slot as unbound (you can use the \
> FrameDescriptor's default value for that). In your variable access node, you should \
> then check in the Object specialization that the slot is bound (e.g. \
> getObject(slot) != null); in primitive type specializations, the guard (e.g. \
> isLong(slot)) already implies it is bound. The check can be omitted for statically \
> bound variables (known at parse time). 
> Minimalist example:
> 
> public abstract class ReadVarNode extends Node {
> final FrameSlot slot;
> static final UNBOUND = null;
> 
> ReadVarNode(FrameSlot slot) {
> this.slot = slot;
> }
> 
> public abstract Object execute(VirtualFrame frame);
> public abstract long executeLong(VirtualFrame frame) throws \
> UnexpectedResultException; 
> @Specialization(guards = "frame.isLong(slot)")
> long readLocalLong(VirtualFrame frame) {
> return FrameUtil.getLongSafe(frame, slot);
> }
> 
> @Specialization(guards = "frame.isObject(slot)")
> Object readLocalObject(VirtualFrame frame) {
> Object value = FrameUtil.getObjectSafe(frame, slot);
> if (value == UNBOUND) {
> throw /* unbound name exception */;
> }
> return value;
> }
> }
> 
> Hope this helps. Let us know if you have further questions.
> 
> - Andreas
> 
> ----- Original Message -----
> From: kovariadam@gmail.com
> To: graal-dev@openjdk.java.net
> Sent: Tuesday, February 5, 2019 9:05:15 PM GMT +01:00 Amsterdam / Berlin / Bern / \
>                 Rome / Stockholm / Vienna
> Subject: Identifying bound/free name in a FrameDescriptor
> 
> Hello,
> 
> I have usecase concerning recursive calls (thus, as I noticed, one
> instance of FrameDescriptor which is being reused for recursive calls)
> and detecting whether a variable is bound or free within that
> particular invocation.
> 
> For example, this simple recursive function:
> 
> factorial 1 = 1
> factorial n = n * (factorial n - 1)
> 
> then:
> 
> factorial 5
> 
> In the first invocation, this function's FrameDescriptor would not
> contain "n", but in the next call to itself, it will, because it will
> be written to local stack in the second line.
> The situation is, when in second invocation of this recursive
> function, the FrameSlot for "n" will exist, so something like:
> 
> VirtualFrame.getFrameDescriptor().findFrameSlot("n")
> 
> will return true, however, the value will be null and code such as this one:
> 
> FrameUtil.getLongSafe(frame, getSlot())
> 
> will end up throwing an IllegalStateException.
> 
> 
> That said, I think I understand that this is because the
> FrameDescriptor is being reused here, my question is, how to
> effectively decide whether a name is bound or not, that would not
> involve findFrameSlot or catching IllegalStateException.
> 
> 
> 
> I hope my example can be understood, please let me know if it is
> unclear. I will appreciate any feedback.
> 
> 
> Thanks,
> 
> --
> Adam Kovari(mailto:kovariadam@gmail.com)



-- 
---
Adam Kovari(mailto:kovariadam@gmail.com)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic