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

Issue for inconsistent result #126

Open
yiming-tang-cs opened this issue Dec 8, 2017 · 17 comments
Open

Issue for inconsistent result #126

yiming-tang-cs opened this issue Dec 8, 2017 · 17 comments
Assignees
Milestone

Comments

@yiming-tang-cs
Copy link
Contributor

yiming-tang-cs commented Dec 8, 2017

If the test case is:

package p;

import java.util.HashSet;
import java.util.stream.*;

import edu.cuny.hunter.streamrefactoring.annotations.*;

class A {

	Stream<Object> m() {
		Stream<Object> stream = new HashSet<>().stream().parallel();
		return stream;
	}

	@EntryPoint
	void n() {
		Stream<Object> s = m();
		s.distinct().count();
	}
}

there are two elements in execution modes:

stream start pos length method type FQN execution mode
new HashSet<>().stream() 192 24 m() p.A SEQUENTIAL
new HashSet<>().stream() 192 24 m() p.A PARALLEL
@yiming-tang-cs
Copy link
Contributor Author

yiming-tang-cs commented Dec 8, 2017

Related to #103

@khatchad
Copy link
Member

Seems related to b8d3815.

@khatchad
Copy link
Member

The table is quite helpful but I'm confused as to why this would happen with b8d3815 present. @saledouble Please verify that you have b8d3815 in your fork. In fact, please be even with origin/master and try again

@khatchad
Copy link
Member

Hm, I just merged #124 locally and it passed. Investigating ...

@khatchad
Copy link
Member

So m() is not supposed to be considered as a stream creation method. Given that testNonInternalAPI3() passes, it must have something to do with the sorted() being called immediately prior to returning the stream.

@khatchad khatchad mentioned this issue Dec 18, 2017
khatchad added a commit that referenced this issue Dec 18, 2017
@khatchad khatchad assigned khatchad and unassigned yiming-tang-cs Dec 18, 2017
@khatchad
Copy link
Member

khatchad commented Dec 18, 2017

After investigating, the typestate analysis is resulting in bottom states for the same stream for which it deemed to be ordered. So, we get two different possible states without any branching, which seems incorrect:

INFO: Factoid: (SITE_IN_NODE{< Primordial, Ljava/util/stream/StreamSupport, stream(Ljava/util/Spliterator;Z)Ljava/util/stream/Stream; >:NEW <Primordial,Ljava/util/stream/ReferencePipeline$Head>@5 in CallStringContext: [ java.util.Collection.stream()Ljava/util/stream/Stream;@7 p.A.m()Ljava/util/stream/Stream;@7 ]},[name: bottom, accepting: false],unique)
INFO: Factoid: (SITE_IN_NODE{< Primordial, Ljava/util/stream/StreamSupport, stream(Ljava/util/Spliterator;Z)Ljava/util/stream/Stream; >:NEW <Primordial,Ljava/util/stream/ReferencePipeline$Head>@5 in CallStringContext: [ java.util.Collection.stream()Ljava/util/stream/Stream;@7 p.A.m()Ljava/util/stream/Stream;@7 ]},[name: ordered, accepting: false],unique)

@khatchad
Copy link
Member

Does not seem related to #127. I also tried switching the live analysis SAFE option on with no change in the results.

@khatchad
Copy link
Member

At this point, we should probably have a dive into the SAFE code to see why it is assigning both the bottom state and the ordered state to the stream instance in question.

@khatchad
Copy link
Member

I'm also wondering if it has something to do with the change for #103. Are we now analyzing blocks that make no sense? It would be good to debug this to find out

@khatchad
Copy link
Member

khatchad commented Dec 19, 2017 via email

khatchad added a commit that referenced this issue Dec 19, 2017
@khatchad
Copy link
Member

khatchad commented Dec 19, 2017

Doesn't seem to depend on blocks:

Dec 18, 2017 8:27:23 PM edu.cuny.hunter.streamrefactoring.core.analysis.StreamStateMachine start
INFO: Adding state: [name: bottom, accepting: false] for instance: SITE_IN_NODE{< Primordial, Ljava/util/stream/StreamSupport, stream(Ljava/util/Spliterator;Z)Ljava/util/stream/Stream; >:NEW <Primordial,Ljava/util/stream/ReferencePipeline$Head>@5 in CallStringContext: [ java.util.Collection.stream()Ljava/util/stream/Stream;@7 p.A.m()Ljava/util/stream/Stream;@7 ]} for block: BB[SSA:5..5]3 - p.A.n()V for rule: ordering

Dec 18, 2017 8:27:23 PM edu.cuny.hunter.streamrefactoring.core.analysis.StreamStateMachine start
INFO: Adding state: [name: ordered, accepting: false] for instance: SITE_IN_NODE{< Primordial, Ljava/util/stream/StreamSupport, stream(Ljava/util/Spliterator;Z)Ljava/util/stream/Stream; >:NEW <Primordial,Ljava/util/stream/ReferencePipeline$Head>@5 in CallStringContext: [ java.util.Collection.stream()Ljava/util/stream/Stream;@7 p.A.m()Ljava/util/stream/Stream;@7 ]} for block: BB[SSA:5..5]3 - p.A.n()V for rule: ordering

@khatchad
Copy link
Member

Here's the IR:

Dec 18, 2017 8:01:58 PM edu.cuny.hunter.streamrefactoring.core.analysis.StreamStateMachine start
INFO: IR is: < Application, Lp/A, n()V >
CFG:
BB0[-1..-2]
    -> BB1
BB1[0..1]
    -> BB2
    -> BB5
BB2[2..4]
    -> BB3
    -> BB5
BB3[5..5]
    -> BB4
    -> BB5
BB4[6..7]
    -> BB5
BB5[-1..-2]
Instructions:
BB0
BB1
1   v4 = invokevirtual < Application, Lp/A, m()Ljava/util/stream/Stream; > v1 @1 exception:v3(line 17)
BB2
4   v6 = invokeinterface < Application, Ljava/util/stream/Stream, distinct()Ljava/util/stream/Stream; > v4 @6 exception:v5(line 18)
BB3
5   v8 = invokeinterface < Application, Ljava/util/stream/Stream, count()J > v6 @11 exception:v7(line 18)
BB4
7   return                                   (line 19)
BB5

@khatchad
Copy link
Member

No clue.

@khatchad
Copy link
Member

Maybe we should just fall back to ordered.

@khatchad
Copy link
Member

It is almost like it's treating the return value from the client method as a new instance ...

@khatchad
Copy link
Member

It has something to do with the terminal operation, i.e., where it is called. It seems to work fine when the terminal operation is called in the same method as the transitioning method. The terminal operation corresponds to the block where we extract the typestate information (i.e., it is the state of the object at that block).

khatchad added a commit that referenced this issue Dec 19, 2017
@khatchad
Copy link
Member

I am trying out different solvers but they are taking way too long. We may have to wait for the performance improvements in #103.

@khatchad khatchad added this to the Future milestone Dec 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants