Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small convenience improvements for Instrumentation API #24

Conversation

smarr
Copy link
Contributor

@smarr smarr commented Jan 29, 2016

No description provided.

This is a concenience method to correct the tags of a source section at a later point, for instance during paring.

In my handwritten recursive descent parser, I don't know the complete context during parsing (i could pass it in, but that would make things more complicated), so, I would like to be able to change the tags of a subexpression when I am back in the parent expression where I assemble the AST.

Signed-off-by: Stefan Marr <git@stefan-marr.de>
(identifier != null ? " identifier=" + identifier : "") + " code=" + getCode();
}
if (tags != null && tags.length > 0) {
result = " tags: " + Arrays.toString(tags);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a += ,right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did that ever work? hm, probably it didn't. yes, you are right. will fix.

Show the tags in the string representation, helpful for debugging.

Signed-off-by: Stefan Marr <git@stefan-marr.de>
@smarr smarr force-pushed the feature/instrumentation_api branch from 6694614 to 3a51395 Compare January 29, 2016 18:19
@smarr
Copy link
Contributor Author

smarr commented Jan 31, 2016

I think this needs more discussion before merging.
Points raised elsewhere:

  • should tags be kept here as a mutable field?
  • should source sections be unique?

For the last point, this is something I wonder, but doesn't seem to make a lot of sense. Unique source sections, i.e., only one object and one set of tags for a give range. This seems problematic because it might be language dependent or specific to parser/AST structure. Also overlapping source sections are easily constructed, also for identical range. Would be hard to guarantee uniqueness.

@@ -292,6 +299,16 @@ public boolean equals(Object obj) {
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing Javadoc.

@chumer
Copy link
Member

chumer commented Feb 1, 2016

should tags be kept here as a mutable field?

No. SourceSection must be immutable. It is used in HashMaps as key a lot. Since nodes are mutable already its not a big deal if Node#sourceSection is mutable instead.

should source sections be unique?

Unique for a particular Source, or globally unique? I don't think we need that. A proper Equality check is good enough I believe.

@mlvdv
Copy link
Contributor

mlvdv commented Feb 1, 2016

@chumer you mentioned using SourceSection in HashMaps, but haven't responded to my question in the instrumentation review about how tags affect equality. The current overrides of hashcode() and equals() ignore tags.

@smarr
Copy link
Contributor Author

smarr commented Feb 1, 2016

For my use cases, I actually added tags to the hash (prime * result + Arrays.hashCode(tags)) and to the quality (return Arrays.equals(tags, other.tags);).

With respect to the 'uniqueness' discussion above, I feel that makes most sense.

@mlvdv
Copy link
Contributor

mlvdv commented Feb 1, 2016

Might adding tags to the hash make SourceSection unsuitable for building maps of source locations that ignore tags? In the new Instrumentation code there is no longer any way to "remember" locations in guest language code other than SourceSection querying. So if the hashcode includes tags, then changing tags causes existing queries stop matching places where they originally matched, and this is true for all clients.

I continue to see evidence that forcing storage of tags into the SourceSection is inappropriate. A "tag" is conceptually a different kind of information, as I've described in a Skype chat about Instrumentation. It doesn't say anything fundamental about the program, only that some tool has been instructed to behave a certain way in this particular situation. Some clients will care about this, others will not. We're already discovering that the binding times for the two kinds of information are quite different; the need to "replace" information that has already been recorded is a clue.

@smarr
Copy link
Contributor Author

smarr commented Feb 2, 2016

Hm, source section querying? Do you have an example for what that is used?

Building the DynamicMetrics tool, I actually found a couple of things that surprised me.

For instance, I annotated message sends, and I annotated field reads. In Newspeak (SOMns) there is however no separate syntax for field reads. So, I end up with two different source sections for the same piece of source code. One annotated as message send, and one annotated as field read.

In the tool that actually works nicely. I render field reads as blue, and sends as italic. That combines nicely. And, as a reader of this highlighted code, I get a lot of information.

However, some might say, I abuse the instrumentation framework by exposing such dynamic information. But I tend to disagree. It works very nicely for me.

But back to the question, in such a scenario, what would you be querying for, and which of the source sections would you want? or perhaps both?

@smarr smarr added the on hold label Feb 2, 2016
@mlvdv
Copy link
Contributor

mlvdv commented Feb 5, 2016

Source section querying:

The user sets a breakpoint (e.g. "the statement on line 42 in some source") and expects feedback whether the specified location actually exists. "Don't know yet" is sometimes the right answer. The debugger must (and already does) do extra work to manage "unresolved" breakpoints for files that haven't been loaded. But the feedback is an important usability issue. If the user thinks the location exists, but incorrectly, behavior is mysterious: an instance of the well-known "hidden state" usability failure.

@mlvdv
Copy link
Contributor

mlvdv commented Feb 5, 2016

For instance, I annotated message sends, and I annotated field reads. In Newspeak (SOMns) there is however no separate syntax for field reads. So, I end up with two different source sections for the same piece of source code. One annotated as message send, and one annotated as field read.

This came up when I was working with the Irvine Python people: two nodes can (correctly) have the same SourceSection. In your case, querying with one tag or the other gets you the right location.
Getting multiple "locations" is also a reasonable result that can reveal something in the case you mention, for example if your query had both tags or just specified "any" tag.

I'll propose a stronger requirement: a client must be able to distinguish between the case where (when all SourceSections are the same) a single node has two tags and where two separate node each have one of the tags.

@mlvdv
Copy link
Contributor

mlvdv commented Feb 5, 2016

However, some might say, I abuse the instrumentation framework by exposing such dynamic information. But I tend to disagree. It works very nicely for me.

I strongly disagree with what "some might say"! I've been trying to get information out of source code and in front of programmers usefully for many years; that's the whole point of the Instrumentation framework. It is also why I argue constantly for flexibility and openness in the APIs: I named it a "Framework" and I refer to it as a "tool kit". Anybody should be able to create, as easily as possible, developer tools we have not yet imagined.

@chumer
Copy link
Member

chumer commented Feb 9, 2016

I will add hashCode, toString and equals implementation to SourceSection for tags. I missed that, thanks.
A cloneWithTags makes sense as well will add that. But with a little more documentation and testing.

Ok if I close this pull-request?

@mlvdv with the EventNodeFactory you can map mulitple "AST location" to one and the same SourceSection. If you care about same SourceSections beeing different in a Map you can use an IdentityHashMap in your tool implementation.

@smarr
Copy link
Contributor Author

smarr commented Feb 9, 2016

Ok, closing it.

@smarr smarr closed this Feb 9, 2016
@jtulach
Copy link
Contributor

jtulach commented Feb 9, 2016

Veto: I am against the name cloneWithTags, I am OK with withTags.

@chumer
Copy link
Member

chumer commented Feb 9, 2016

Ok. Will add withTags.

@mlvdv
Copy link
Contributor

mlvdv commented Feb 17, 2016

@chumer

@mlvdv with the EventNodeFactory you can map mulitple "AST location" to one and the same SourceSection. If you care about same SourceSections beeing different in a Map you can use an IdentityHashMap in your tool implementation.

If I were to use an IdentityHashMap in that fashion, what guarantee would I be depending on about SourceSection identity:

  • where would this guarantee be documented?
  • how would this guarantee be enforced for language implementations, since they are responsible for creating and assigning SourceSection objects?

dougxc pushed a commit that referenced this pull request Apr 22, 2016
…dary to master

* commit 'f5dac94d8934f7d0425e3ebf469d31dff82cefb5':
  Call ThreadLocal<ContextStore>.get() via TruffleBoundary
@smarr smarr deleted the feature/instrumentation_api branch June 22, 2016 13:26
rkennke pushed a commit to rkennke/graal that referenced this pull request Apr 30, 2021
* Fix writing of unnamed module

* Ignore empty package; serialize null-class-loader as 'bootstrap'

* Fix checkstyle complaint

* Handle null string in JfrSymbolRepository as 0 ID/reference

* Don't special-case 'null' module name, serialize it as 0
simonis pushed a commit to simonis/graal that referenced this pull request Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants