Skip to content

Commit

Permalink
added cfBlockEnter cfBlockExit to mark the enter and exit of a contro…
Browse files Browse the repository at this point in the history
…l flow block (including if,loops,switch)
  • Loading branch information
Haiyang-Sun committed Sep 17, 2019
1 parent 4293fa1 commit 4007d05
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/ch.usi.inf.nodeprof/js/analysis/forinof/analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
this.forObjectPost = function (iid, isForIn) {
console.log('forObjectPost@', J$.iidToLocation(iid), isForIn);
}
this.cfBlockEnter = function(iid) {
console.log('iterationEnter@', J$.iidToLocation(iid));
}
this.cfBlockExit = function(iid) {
console.log('iterationExit@', J$.iidToLocation(iid));
}
this.endExpression = function (iid, type, result) {
lastExprResult = result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
forObject@ (src/ch.usi.inf.nodeprof.test/js/minitests/forinof.js:6:1:7:2) true { x: 'valueX', y: 'valueY' }
iterationEnter@ (src/ch.usi.inf.nodeprof.test/js/minitests/forinof.js:6:1:7:2)
iterationExit@ (src/ch.usi.inf.nodeprof.test/js/minitests/forinof.js:6:1:7:2)
iterationEnter@ (src/ch.usi.inf.nodeprof.test/js/minitests/forinof.js:6:1:7:2)
iterationExit@ (src/ch.usi.inf.nodeprof.test/js/minitests/forinof.js:6:1:7:2)
forObjectPost@ (src/ch.usi.inf.nodeprof.test/js/minitests/forinof.js:6:1:7:2) true
forObject@ (src/ch.usi.inf.nodeprof.test/js/minitests/forinof.js:11:1:12:2) false [ 41, 42, 43 ]
iterationEnter@ (src/ch.usi.inf.nodeprof.test/js/minitests/forinof.js:11:1:12:2)
iterationExit@ (src/ch.usi.inf.nodeprof.test/js/minitests/forinof.js:11:1:12:2)
iterationEnter@ (src/ch.usi.inf.nodeprof.test/js/minitests/forinof.js:11:1:12:2)
iterationExit@ (src/ch.usi.inf.nodeprof.test/js/minitests/forinof.js:11:1:12:2)
iterationEnter@ (src/ch.usi.inf.nodeprof.test/js/minitests/forinof.js:11:1:12:2)
iterationExit@ (src/ch.usi.inf.nodeprof.test/js/minitests/forinof.js:11:1:12:2)
forObjectPost@ (src/ch.usi.inf.nodeprof.test/js/minitests/forinof.js:11:1:12:2) false
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright 2018 Dynamic Analysis Group, Università della Svizzera Italiana (USI)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package ch.usi.inf.nodeprof.handlers;

import com.oracle.truffle.api.instrumentation.EventContext;

import ch.usi.inf.nodeprof.ProfiledTagEnum;

public abstract class CFBlockEventHandler extends BaseSingleTagEventHandler {
public CFBlockEventHandler(EventContext context) {
super(context, ProfiledTagEnum.CF_BLOCK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import ch.usi.inf.nodeprof.jalangi.factory.BinaryFactory;
import ch.usi.inf.nodeprof.jalangi.factory.ReturnFactory;
import ch.usi.inf.nodeprof.jalangi.factory.BuiltinFactory;
import ch.usi.inf.nodeprof.jalangi.factory.CFBlockFactory;
import ch.usi.inf.nodeprof.jalangi.factory.ConditionalFactory;
import ch.usi.inf.nodeprof.jalangi.factory.DeclareFactory;
import ch.usi.inf.nodeprof.jalangi.factory.EvalFactory;
Expand Down Expand Up @@ -123,10 +124,14 @@ public class JalangiAnalysis {
put("forObject", EnumSet.of(CF_ROOT));
put("forObjectPost", EnumSet.of(CF_ROOT));

put("cfBlockEnter", EnumSet.of(CF_BLOCK));
put("cfBlockExit", EnumSet.of(CF_BLOCK));

put("_return", EnumSet.of(CF_BRANCH));

put("startExpression", EnumSet.of(EXPRESSION));
put("endExpression", EnumSet.of(EXPRESSION));

}
});

Expand Down Expand Up @@ -279,8 +284,6 @@ public void onReady() {
}

/**
* TODO
*
* Loop not tested
*/
if (this.callbacks.containsKey("loopEnter") || this.callbacks.containsKey("loopExit")) {
Expand All @@ -289,6 +292,15 @@ public void onReady() {
new LoopFactory(this.jsAnalysis, callbacks.get("loopEnter"), callbacks.get("loopExit")));
}

/**
* cfBlockEnter, cfBlockExit
*/
if (this.callbacks.containsKey("cfBlockEnter") || this.callbacks.containsKey("cfBlockExit")) {
this.instrument.onCallback(
ProfiledTagEnum.CF_BLOCK,
new CFBlockFactory(this.jsAnalysis, callbacks.get("cfBlockEnter"), callbacks.get("cfBlockExit")));
}

/**
* _return callback
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*******************************************************************************
* Copyright 2018 Dynamic Analysis Group, Università della Svizzera Italiana (USI)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package ch.usi.inf.nodeprof.jalangi.factory;

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.instrumentation.EventContext;
import com.oracle.truffle.api.nodes.DirectCallNode;
import com.oracle.truffle.api.object.DynamicObject;

import ch.usi.inf.nodeprof.handlers.BaseEventHandlerNode;
import ch.usi.inf.nodeprof.handlers.CFBlockEventHandler;

public class CFBlockFactory extends AbstractFactory {
public CFBlockFactory(Object jalangiAnalysis, DynamicObject pre, DynamicObject post) {
super("cfblock", jalangiAnalysis, pre, post, 1, 1);
}

@Override
public BaseEventHandlerNode create(EventContext context) {
return new CFBlockEventHandler(context) {
@Child DirectCallNode preCall = createPreCallNode();
@Child DirectCallNode postCall = createPostCallNode();

@Override
public void executePre(VirtualFrame frame, Object[] inputs) {
if (pre != null) {
setPreArguments(0, getSourceIID());
// TODO
// add information about the type of the block (if, iteration, switch)
directCall(preCall, true, getSourceIID());
}
}

@Override
public void executePost(VirtualFrame frame, Object result,
Object[] inputs) {
if (post != null) {
setPostArguments(0, getSourceIID());
// TODO
// add information about the type of the block (if, iteration, switch)
directCall(postCall, false, getSourceIID());
}
}
};
}

}

0 comments on commit 4007d05

Please sign in to comment.