Permalink
Browse files

V 0.7.1

	deleted:    .#d.txt
	modified:   examples/kilim/examples/HttpFileServer.java
	modified:   src/kilim/Mailbox.java
	modified:   src/kilim/analysis/AsmDetector.java
	modified:   src/kilim/analysis/BasicBlock.java
	modified:   src/kilim/analysis/CallWeaver.java
	modified:   src/kilim/analysis/ClassFlow.java
	modified:   src/kilim/analysis/ClassWeaver.java
	modified:   src/kilim/analysis/Detector.java
	modified:   src/kilim/analysis/FileLister.java
	modified:   src/kilim/analysis/Frame.java
	modified:   src/kilim/analysis/MethodFlow.java
	modified:   src/kilim/analysis/MethodWeaver.java
	modified:   src/kilim/analysis/TypeDesc.java
	modified:   src/kilim/analysis/Value.java
	modified:   src/kilim/http/HttpSession.java
	new file:   src/kilim/mirrors/ClassMirror.java
	new file:   src/kilim/mirrors/ClassMirrorNotFoundException.java
	new file:   src/kilim/mirrors/FieldMirror.java
	new file:   src/kilim/mirrors/MemberMirror.java
	new file:   src/kilim/mirrors/MethodMirror.java
	new file:   src/kilim/mirrors/Mirrors.java
	new file:   src/kilim/mirrors/RuntimeClassMirrors.java
	modified:   src/kilim/nio/EndPoint.java
	modified:   src/kilim/tools/DumpClass.java
	modified:   src/kilim/tools/FlowAnalyzer.java
	modified:   src/kilim/tools/Weaver.java
	modified:   test/kilim/test/Base.java
	modified:   test/kilim/test/TestInvalidPausables.java
  • Loading branch information...
sriram-srinivasan committed Apr 7, 2010
1 parent 4bb92e3 commit aa68747588afe97cfd22381e5ed1d672c2228a21
View
@@ -50,6 +50,7 @@ public static void main(String[] args) throws IOException {
// create a listener on port 7262. An instance of HttpFileServer is created upon
// every new socket connection to this port.
new HttpServer(7262, HttpFileServer.class);
+ System.out.println("HttpFileServer listening on http://localhost:7262");
}
public static void usage() {
@@ -98,25 +99,31 @@ private File urlToPath(HttpRequest req) {
}
public boolean check(HttpResponse resp, File file) throws IOException, Pausable {
- if (!file.exists())
- problem(file, resp, HttpResponse.ST_NOT_FOUND, "File Not Found");
- else if (!file.canRead()) {
- problem(file, resp, HttpResponse.ST_FORBIDDEN, "Unable to read file");
+ byte[] status = HttpResponse.ST_OK;
+ String msg = "";
+
+ if (!file.exists()) {
+ status = HttpResponse.ST_NOT_FOUND;
+ msg = "File Not Found: " + file.getName();
+ } else if (!file.canRead()) {
+ status = HttpResponse.ST_FORBIDDEN;
+ msg = "Unable to read file " + file.getName();
} else {
try {
String path = file.getCanonicalPath();
if (!path.startsWith(baseDirectoryName)) {
throw new SecurityException();
}
} catch (Exception e) {
- problem(file, resp, HttpResponse.ST_FORBIDDEN, "Error: " + e.getMessage());
+ status = HttpResponse.ST_FORBIDDEN;
+ msg = "Error retrieving " + file.getName() + ":<br>" + e.getMessage();
}
}
- if (resp.status == HttpResponse.ST_OK) {
- return true;
- } else {
- super.sendResponse(resp);
+ if (status != HttpResponse.ST_OK) {
+ problem(file, resp, status, msg);
return false;
+ } else {
+ return true;
}
}
@@ -154,7 +161,7 @@ public void sendDirectory(HttpResponse resp, File file, boolean headOnly) throws
p.print(relDir);
p.print("</title></head><body ");
p.print("><h2>Index of ");
- p.print(relDir);
+ p.print(relDir.equals(".") ? "/" : relDir);
p.print("</h2>");
String names[] = file.list();
if (names == null) {
@@ -171,7 +178,7 @@ public void sendDirectory(HttpResponse resp, File file, boolean headOnly) throws
p.print("</a><br>");
}
}
- p.print("</body>");
+ p.print("</body></html>");
p.flush();
super.sendResponse(resp);
}
@@ -186,7 +193,8 @@ private String getRelPath(File file) throws IOException {
if (!path.startsWith(baseDirectoryName)) {
throw new SecurityException();
}
- return path.substring(baseDirectoryName.length()); // include the "/"
+ path = path.substring(baseDirectoryName.length()); // include the "/"
+ return (path.length() == 0) ? "." : path;
}
public static HashMap<String, String> mimeTypes = new HashMap<String, String>();
View
@@ -77,8 +77,7 @@ public T get(EventSubscriber eo) {
int n = numMsgs;
if (n > 0) {
int ic = icons;
- msg = msgs[ic];
- msgs[ic] = null;
+ msg = msgs[ic]; msgs[ic]=null;
icons = (ic + 1) % msgs.length;
numMsgs = n - 1;
@@ -180,7 +179,7 @@ public T get() throws Pausable{
public T get(long timeoutMillis) throws Pausable {
final Task t = Task.getCurrentTask();
T msg = get(t);
- long begin = System.currentTimeMillis();
+ long end = System.currentTimeMillis() + timeoutMillis;
while (msg == null) {
TimerTask tt = new TimerTask() {
public void run() {
@@ -191,10 +190,14 @@ public void run() {
Task.timer.schedule(tt, timeoutMillis);
Task.pause(this);
tt.cancel();
- if (System.currentTimeMillis() - begin > timeoutMillis) {
+
+ msg = get(t);
+
+ timeoutMillis = end - System.currentTimeMillis();
+ if (timeoutMillis <= 0) {
+ removeMsgAvailableListener(t);
break;
}
- msg = get(t);
}
return msg;
}
@@ -235,7 +238,7 @@ public synchronized void removeSpaceAvailableListener(EventSubscriber spcSub) {
public synchronized void addMsgAvailableListener(EventSubscriber msgSub) {
- if (sink != null) {
+ if (sink != null && sink != msgSub) {
throw new AssertionError(
"Error: A mailbox can not be shared by two consumers. New = "
+ msgSub + ", Old = " + sink);
@@ -16,7 +16,7 @@
public class AsmDetector {
static HashMap<String, ClassCache> classCacheMap= new HashMap<String, ClassCache>();
public static int getPausableStatus(String className, String methodName,
- String desc)
+ String desc, Detector detector)
{
try {
ClassCache classCache = classCacheMap.get(className);
@@ -30,7 +30,7 @@ public static int getPausableStatus(String className, String methodName,
if (status == Detector.METHOD_NOT_FOUND) {
// check super classes
for (String superName: classCache.superClasses) {
- status = Detector.getPausableStatus(superName, methodName, desc);
+ status = detector.getPausableStatus(superName, methodName, desc);
if (status != Detector.METHOD_NOT_FOUND)
break;
}
@@ -64,7 +64,7 @@ private static ClassCache cache(String className, ClassNode cn) {
return classCache;
}
public static void main(String[] args) {
- AsmDetector.getPausableStatus("com/sleepycat/je/Database", "putInternal", "Lcom/sleepycat/je/Transaction;Lcom/sleepycat/je/DatabaseEntry;Lcom/sleepycat/je/DatabaseEntry;Lcom/sleepycat/je/dbi/PutMode;Lkilim/Fiber;)Lcom/sleepycat/je/OperationStatus;)V");
+ AsmDetector.getPausableStatus("com/sleepycat/je/Database", "putInternal", "Lcom/sleepycat/je/Transaction;Lcom/sleepycat/je/DatabaseEntry;Lcom/sleepycat/je/DatabaseEntry;Lcom/sleepycat/je/dbi/PutMode;Lkilim/Fiber;)Lcom/sleepycat/je/OperationStatus;)V", Detector.DEFAULT);
}
static class ClassCache {
@@ -86,6 +86,7 @@ public int getPausableStatus(String methodName, String desc) {
return Detector.METHOD_NOT_FOUND;
}
}
+ @Override
public String toString() {
return className + "\nPausable Methods: " + pausableMethods + "\nOthers:" + otherMethods;
}
@@ -4,8 +4,6 @@
* specified in the file "License"
*/
package kilim.analysis;
-import kilim.*;
-
import static kilim.Constants.D_ARRAY_BOOLEAN;
import static kilim.Constants.D_ARRAY_BYTE;
import static kilim.Constants.D_ARRAY_CHAR;
@@ -25,8 +23,8 @@
import static kilim.Constants.D_RETURN_ADDRESS;
import static kilim.Constants.D_SHORT;
import static kilim.Constants.D_VOID;
-import static kilim.Constants.THROWABLE_CLASS;
import static kilim.Constants.TASK_CLASS;
+import static kilim.Constants.THROWABLE_CLASS;
import static org.objectweb.asm.Opcodes.*;
import java.util.ArrayList;
@@ -37,6 +35,8 @@
import java.util.List;
import java.util.Stack;
+import kilim.KilimException;
+
import org.objectweb.asm.Label;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.FieldInsnNode;
@@ -220,6 +220,10 @@ public BasicBlock(MethodFlow aflow, Label aStartLabel) {
successors = new ArrayList<BasicBlock>(2);
}
+ Detector detector() {
+ return flow.detector();
+ }
+
/**
* Absorb as many instructions until the next label or the next transfer of
* control instruction. In the first pass we may end up creating many many
@@ -232,6 +236,7 @@ public BasicBlock(MethodFlow aflow, Label aStartLabel) {
* 3. A pausable method is treated like a labeled instruction, and is
* given a label if there isn't one already. Constraint 2 applies.
*/
+ @SuppressWarnings("unchecked")
int initialize(int pos) {
AbstractInsnNode ain;
startPos = pos;
@@ -318,15 +323,15 @@ int initialize(int pos) {
case TABLESWITCH:
case LOOKUPSWITCH:
Label defaultLabel;
- List otherLabels;
+ List<Label> otherLabels;
if (opcode == TABLESWITCH) {
defaultLabel = ((TableSwitchInsnNode) ain).dflt;
otherLabels = ((TableSwitchInsnNode) ain).labels;
} else {
defaultLabel = ((LookupSwitchInsnNode) ain).dflt;
otherLabels = ((LookupSwitchInsnNode) ain).labels;
}
- for (Iterator it = otherLabels.iterator(); it.hasNext();) {
+ for (Iterator<Label> it = otherLabels.iterator(); it.hasNext();) {
l = (Label) it.next();
addSuccessor(flow.getOrCreateBasicBlock(l));
}
@@ -355,6 +360,9 @@ int initialize(int pos) {
break;
default:
+ if (opcode >= 26 && opcode <= 45)
+ throw new IllegalStateException("instruction variants not expected here");
+
break;
}
@@ -476,6 +484,7 @@ void interpret() {
frame.push(Value.make(startPos, D_RETURN_ADDRESS));
}
String componentType = null;
+ @SuppressWarnings("unused")
boolean canThrowException = false;
boolean propagateFrame = true;
int i = 0;
@@ -1078,16 +1087,16 @@ void interpret() {
}
}
-
+ /*
private boolean checkReceiverType(Value v, MethodInsnNode min) {
String t = v.getTypeDesc();
if (t == D_NULL) {
return true;
}
t = TypeDesc.getInternalName(t);
- return Detector.getPausableStatus(t, min.name, min.desc) != Detector.METHOD_NOT_FOUND;
+ return detector().getPausableStatus(t, min.name, min.desc) != Detector.METHOD_NOT_FOUND;
}
-
+ */
public boolean isCatchHandler() {
return caughtExceptionType != null;
}
@@ -1402,6 +1411,7 @@ BasicBlock getFollowingBlock() {
return flow.getBasicBlock(l);
}
+ @Override
public String toString() {
StringBuffer sb = new StringBuffer(200);
sb.append("\n========== BB #").append(id).append("[").append(System.identityHashCode(this)).append("]\n");
@@ -297,7 +297,6 @@ int getNumBottom() {
*/
void genRewind(MethodVisitor mv) {
Frame f = bb.startFrame;
- Usage u = bb.usage;
// The last parameter to the method is fiber, but the original
// code doesn't know that and will use up that slot as it
Oops, something went wrong.

1 comment on commit aa68747

@krestenkrab

This comment has been minimized.

Show comment Hide comment
@krestenkrab

krestenkrab Apr 14, 2010

Contributor

Thanks for making this available.

It would have been nice though to be able to trace which edits are from http://github.com/krestenkrab/kilim, and which ones are from your own additions. Hopefully I'll soon have the time to make my kilim a clone of this; and integrate it into Erjang.

In the future; do you intend to drive development on GIT?

Contributor

krestenkrab commented on aa68747 Apr 14, 2010

Thanks for making this available.

It would have been nice though to be able to trace which edits are from http://github.com/krestenkrab/kilim, and which ones are from your own additions. Hopefully I'll soon have the time to make my kilim a clone of this; and integrate it into Erjang.

In the future; do you intend to drive development on GIT?

Please sign in to comment.