Qestion about unbuilt class

27 views
Skip to first unread message

lule...@gmail.com

unread,
Jun 4, 2014, 9:52:27 PM6/4/14
to chord-...@googlegroups.com
I am a new user to Chord and have an easy question. I've just downloaded the latest version of Chord 2.1 (http://pag.gatech.edu/chord).

I just ran an simple "hello_world" program in "example" folder with a simple change as follows.
==============================
====================
package test;

public class HelloWorld {
        public static void main(String[] args) {
                System.out.println("Hello, " + args[0] + "!");
                CLASSA a = new CLASSA();
                CLASSB b = (CLASSB) a;
        }
}

class CLASSA{
}

class CLASSB extends CLASSA {

}
==============================
=====================

To print out all the classes that chord build, I changed the code of
Program.java to let it print all classes name:

====================================================
private void buildClasses() {
        if (methods == null)
            buildMethods();
        assert (classes == null);
        assert (types == null);
        assert (nameToClassMap == null);
        assert (nameToTypeMap == null);
        PrimordialClassLoader loader = PrimordialClassLoader.loader;
        jq_Type[] typesAry = loader.getAllTypes();
        int numTypes = loader.getNumTypes();
        Arrays.sort(typesAry, 0, numTypes, comparator);
        types = new IndexSet<jq_Type>(numTypes + 2);
        classes = new IndexSet<jq_Reference>();
        types.add(jq_NullType.NULL_TYPE);
        types.add(jq_ReturnAddressType.INSTANCE);
        for (int i = 0; i < numTypes; i++) {
            jq_Type t = typesAry[i];
            assert (t != null);
            types.add(t);
            if (t instanceof jq_Reference && t.isPrepared()) {
                jq_Reference r = (jq_Reference) t;
                classes.add(r);
                System.out.println("===== " + r.toString()+ " =====");                <--- my change is here
            }
        }
        buildNameToClassMap();
        buildNameToTypeMap();
    }
=======================================================
Then I built chord and ran it with:

ant -Dchord.work.dir=./examples/hello_world-Dchord.run.analyses=cipa-0cfa-dlog
run

However, the result in log.txt looks like this, I don't know why
CLASSB is not built and is there a way to have CLASSB also be built?

....
===== sun.util.resources.LocaleData$1 =====
===== sun.util.resources.LocaleData$2 =====
===== sun.util.resources.LocaleData$AvailableLocales =====
===== sun.util.resources.LocaleData$LocaleDataResourceBundleControl =====
===== sun.util.resources.OpenListResourceBundle =====
===== test.CLASSA =====                             <---- only CLASSA is built
===== test.HelloWorld =====


Thank you very much,
Lei


Ariel Rabkin

unread,
Jun 5, 2014, 10:45:11 AM6/5/14
to chord-...@googlegroups.com
In some sense, Chord is doing the right thing here. There are no
instances of CLASSB in the program. Chord is able to figure that out
and only print the classes that could actually be created. (Relatedly,
the code you wrote is guaranteed to fail at runtime with a
ClassCastException.)

That said, it is possible to get Chord to consider CLASSB. The thing
you need to tinker with is the "scope" setting -- chord.scope.kind.
Try setting it to 'cha'. Failing that, you might look into creating
your own ScopeBuilder.

--Ari

--
Ari Rabkin asra...@gmail.com
Princeton Computer Science Department

lule...@gmail.com

unread,
Jun 5, 2014, 2:59:27 PM6/5/14
to chord-...@googlegroups.com
Thank you Ari, this is very helpful and makes sense to me. 
Btw,I was noticed that there might be some optimization work that done by joeq. Is there any way to turn it off. 
It seems that joeq has already done SSA for my method, which I might not like to have.

Best,
Lei 

Ravi Mangal

unread,
Jun 5, 2014, 6:42:29 PM6/5/14
to chord-...@googlegroups.com
Hi Lei,

You can set the property chord.ssa to false when invoking your analysis. Thus, you can invoke your analysis as follows:
ant -Dchord.work.dir=./examples/hello_world-Dchord.run.analyses=cipa-0cfa-dlog -Dchord.ssa=false
run


Best,
Ravi


--
You received this message because you are subscribed to the Google Groups "chord-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chord-discus...@googlegroups.com.
To post to this group, send email to chord-...@googlegroups.com.
Visit this group at http://groups.google.com/group/chord-discuss.
For more options, visit https://groups.google.com/d/optout.

Lei Lu

unread,
Jun 6, 2014, 1:55:56 PM6/6/14
to chord-...@googlegroups.com, ravi...@gmail.com
Hello Ravi,

Thank you for your help. I have tried this yesterday by setting
chord.ssa=false, but it didn't work for we, then by reading the source
code, I figured out that I should set "chord.ssa.kind=nophi", but this
is fine.

The problem for me is that it seems to me that no matter I turn on/off
this switch, SSA is always done.

I have a very simple example, suggested by wiki page of SSA
(http://en.wikipedia.org/wiki/Static_single_assignment_form)
=================================
package test;
public class HelloWorld {
public static void main(String[] args) {
int y = 1;
y = 2;
int x = y;
}
}
==================================
and I asked chord to print instruction by executing ant
-Dchord.work.dir=./examples/hello_world
-Dchord.print.classes=test.HelloWorld run
The following is two runs' the output of log.txt whether I set
"chord.ssa.kind=nophi" or "chord.ssa.kind=phi". They are the same and
it seems that SSA is always done.
==================================
Control flow graph for main:([Ljava/lang/String;)V...@test.HelloWorld:
BB0 (ENTRY) (in: <none>, out: BB2)

BB2 (in: BB0 (ENTRY), out: BB1 (EXIT))
1: MOVE_I R3, IConst: 1
2: MOVE_I R4, IConst: 2
3: MOVE_I R2, IConst: 2
4: RETURN_V

BB1 (EXIT) (in: BB2, out: <none>)
==================================

Dig a little deeper, I found that Chord calls
"jq_Method.doSSA(true/false);" (program/Program.java) to set SSA flag,
then I was trying to see what did jq_Method does.
The online resource that I can find about API is a little bit
outdated. (http://joeq.sourceforge.net/apidocs/joeq/Class/jq_Method.html).
No doSSA() function can be found there. Joeq is made as a jar file in
chord release. Followed your online guide
(http://pag-www.gtisc.gatech.edu/chord/user_guide/start.html#id1) to
download chord-libsrc-2.0.tar.gz, but since it is 2.0 version,
jq_Method.doSSA() function also has a different interface.

public static void doSSA() { doSSA = true; }

So, I am just try to know whether it is the case that SSA is always
going to be done. It seems it is for my tests or I am just miserably
misunderstood.

Thanks,
Lei
> You received this message because you are subscribed to a topic in the
> Google Groups "chord-discuss" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/chord-discuss/aq8d0kNLEYg/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to

Ravi Mangal

unread,
Jun 6, 2014, 2:27:17 PM6/6/14
to Lei Lu, chord-...@googlegroups.com
Hi Lei,

Sorry, I was not accurate enough in my previous reply. The property name indeed is chord.ssa.kind. Try setting it to none. Also, for source of joeq and other 3rd party libraries you can look at libsrc folder under https://code.google.com/p/jchord/source/browse/trunk/.
-Ravi

Lei Lu

unread,
Jun 7, 2014, 3:30:43 PM6/7/14
to Ravi Mangal, chord-...@googlegroups.com
Hello Ravi,

No, it's not a problem at all. By setting it to none. Do you mean "chord.ssa.kind=none" or "chord.ssa.kind=" or even not include this line in property file? Thank you for the libsrc info.


Thanks,
Lei
Reply all
Reply to author
Forward
0 new messages