Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
DiSL
DiSL
Commits
2cfae3b5
Commit
2cfae3b5
authored
May 07, 2014
by
Lubomir Bulej
Browse files
dislserver: cleaned up white space to simplify upcoming merges.
parent
6dbfc1f8
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/ch/usi/dag/dislserver/DiSLServer.java
View file @
2cfae3b5
...
...
@@ -12,144 +12,144 @@ import ch.usi.dag.disl.exception.DiSLInMethodException;
public
abstract
class
DiSLServer
{
public
static
final
String
PROP_DEBUG
=
"debug"
;
private
static
final
boolean
debug
=
Boolean
.
getBoolean
(
PROP_DEBUG
);
private
static
final
String
PROP_PORT
=
"dislserver.port"
;
private
static
final
int
DEFAULT_PORT
=
11217
;
private
static
final
int
port
=
Integer
.
getInteger
(
PROP_PORT
,
DEFAULT_PORT
);
private
static
final
String
PROP_TIME_STAT
=
"dislserver.timestat"
;
private
static
final
boolean
timeStat
=
Boolean
.
getBoolean
(
PROP_TIME_STAT
);
private
static
final
String
PROP_CONT
=
"dislserver.continuous"
;
private
static
final
boolean
continuous
=
Boolean
.
getBoolean
(
PROP_CONT
);
private
static
final
String
PROP_BYPASS
=
"dislserver.disablebypass"
;
private
static
final
boolean
bypass
=
!
Boolean
.
getBoolean
(
PROP_BYPASS
);
private
static
final
AtomicInteger
aliveWorkers
=
new
AtomicInteger
();
private
static
final
AtomicLong
instrumentationTime
=
new
AtomicLong
();
private
static
DiSL
disl
;
private
static
ServerSocket
listenSocket
;
//
public
static
void
main
(
final
String
[]
args
)
{
try
{
// use dynamic bypass
disl
=
new
DiSL
(
bypass
);
if
(
debug
)
{
System
.
out
.
println
(
"DiSL: starting instrumentation server..."
);
}
listenSocket
=
new
ServerSocket
(
port
);
if
(
debug
)
{
System
.
out
.
printf
(
"DiSL: listening at %s:%d\n"
,
listenSocket
.
getInetAddress
().
getHostAddress
(),
listenSocket
.
getLocalPort
()
);
}
while
(
true
)
{
final
Socket
newClient
=
listenSocket
.
accept
();
if
(
debug
)
{
System
.
out
.
printf
(
"DiSL: accepting connection from %s:%d\n"
,
newClient
.
getInetAddress
().
getHostAddress
(),
newClient
.
getPort
()
);
}
NetMessageReader
sc
=
new
NetMessageReader
(
newClient
);
aliveWorkers
.
incrementAndGet
();
new
Worker
(
sc
,
disl
).
start
();
}
}
catch
(
final
IOException
ioe
)
{
reportError
(
new
DiSLServerException
(
ioe
));
}
catch
(
final
Throwable
throwable
)
{
reportError
(
throwable
);
}
}
private
static
void
reportInnerError
(
final
Throwable
throwable
)
{
Throwable
cause
=
throwable
.
getCause
();
while
(
cause
!=
null
&&
cause
.
getMessage
()
!=
null
)
{
System
.
err
.
println
(
" Inner error: "
+
cause
.
getMessage
());
cause
=
cause
.
getCause
();
}
}
public
static
void
reportError
(
Throwable
throwable
)
{
if
(
throwable
instanceof
DiSLException
)
{
System
.
err
.
print
(
"DiSL: error"
);
// report during which method it happened
if
(
throwable
instanceof
DiSLInMethodException
)
{
System
.
err
.
printf
(
" (while instrumenting method \"%s\")"
,
throwable
.
getMessage
()
);
// set inner error
throwable
=
throwable
.
getCause
();
}
reportOptionalMessage
(
throwable
);
reportInnerError
(
throwable
);
if
(
debug
)
{
throwable
.
printStackTrace
();
}
}
else
if
(
throwable
instanceof
DiSLServerException
)
{
System
.
err
.
print
(
"DiSL: server error"
);
reportOptionalMessage
(
throwable
);
reportInnerError
(
throwable
);
if
(
debug
)
{
throwable
.
printStackTrace
();
}
}
else
{
// some other exception
System
.
err
.
print
(
"DiSL: fatal error: "
);
throwable
.
printStackTrace
();
}
}
private
static
void
reportOptionalMessage
(
final
Throwable
throwable
)
{
final
String
message
=
throwable
.
getMessage
();
System
.
err
.
println
((
message
!=
null
)
?
": "
+
message
:
""
);
}
public
static
void
workerDone
(
final
long
instrTime
)
{
instrumentationTime
.
addAndGet
(
instrTime
);
if
(
aliveWorkers
.
decrementAndGet
()
==
0
)
{
if
(
timeStat
)
{
System
.
out
.
printf
(
"DiSL: instrumentation took %d milliseconds\n"
,
instrumentationTime
.
get
()
/
1000000
);
}
// no workers - shutdown
if
(!
continuous
)
{
disl
.
terminate
();
if
(
debug
)
{
System
.
out
.
println
(
"DiSL: shutting down instrumentation server..."
);
}
System
.
exit
(
0
);
}
}
}
public
static
final
String
PROP_DEBUG
=
"debug"
;
private
static
final
boolean
debug
=
Boolean
.
getBoolean
(
PROP_DEBUG
);
private
static
final
String
PROP_PORT
=
"dislserver.port"
;
private
static
final
int
DEFAULT_PORT
=
11217
;
private
static
final
int
port
=
Integer
.
getInteger
(
PROP_PORT
,
DEFAULT_PORT
);
private
static
final
String
PROP_TIME_STAT
=
"dislserver.timestat"
;
private
static
final
boolean
timeStat
=
Boolean
.
getBoolean
(
PROP_TIME_STAT
);
private
static
final
String
PROP_CONT
=
"dislserver.continuous"
;
private
static
final
boolean
continuous
=
Boolean
.
getBoolean
(
PROP_CONT
);
private
static
final
String
PROP_BYPASS
=
"dislserver.disablebypass"
;
private
static
final
boolean
bypass
=
!
Boolean
.
getBoolean
(
PROP_BYPASS
);
private
static
final
AtomicInteger
aliveWorkers
=
new
AtomicInteger
();
private
static
final
AtomicLong
instrumentationTime
=
new
AtomicLong
();
private
static
DiSL
disl
;
private
static
ServerSocket
listenSocket
;
//
public
static
void
main
(
final
String
[]
args
)
{
try
{
// use dynamic bypass
disl
=
new
DiSL
(
bypass
);
if
(
debug
)
{
System
.
out
.
println
(
"DiSL: starting instrumentation server..."
);
}
listenSocket
=
new
ServerSocket
(
port
);
if
(
debug
)
{
System
.
out
.
printf
(
"DiSL: listening at %s:%d\n"
,
listenSocket
.
getInetAddress
().
getHostAddress
(),
listenSocket
.
getLocalPort
()
);
}
while
(
true
)
{
final
Socket
newClient
=
listenSocket
.
accept
();
if
(
debug
)
{
System
.
out
.
printf
(
"DiSL: accepting connection from %s:%d\n"
,
newClient
.
getInetAddress
().
getHostAddress
(),
newClient
.
getPort
()
);
}
NetMessageReader
sc
=
new
NetMessageReader
(
newClient
);
aliveWorkers
.
incrementAndGet
();
new
Worker
(
sc
,
disl
).
start
();
}
}
catch
(
final
IOException
ioe
)
{
reportError
(
new
DiSLServerException
(
ioe
));
}
catch
(
final
Throwable
throwable
)
{
reportError
(
throwable
);
}
}
private
static
void
reportInnerError
(
final
Throwable
throwable
)
{
Throwable
cause
=
throwable
.
getCause
();
while
(
cause
!=
null
&&
cause
.
getMessage
()
!=
null
)
{
System
.
err
.
println
(
" Inner error: "
+
cause
.
getMessage
());
cause
=
cause
.
getCause
();
}
}
public
static
void
reportError
(
Throwable
throwable
)
{
if
(
throwable
instanceof
DiSLException
)
{
System
.
err
.
print
(
"DiSL: error"
);
// report during which method it happened
if
(
throwable
instanceof
DiSLInMethodException
)
{
System
.
err
.
printf
(
" (while instrumenting method \"%s\")"
,
throwable
.
getMessage
()
);
// set inner error
throwable
=
throwable
.
getCause
();
}
reportOptionalMessage
(
throwable
);
reportInnerError
(
throwable
);
if
(
debug
)
{
throwable
.
printStackTrace
();
}
}
else
if
(
throwable
instanceof
DiSLServerException
)
{
System
.
err
.
print
(
"DiSL: server error"
);
reportOptionalMessage
(
throwable
);
reportInnerError
(
throwable
);
if
(
debug
)
{
throwable
.
printStackTrace
();
}
}
else
{
// some other exception
System
.
err
.
print
(
"DiSL: fatal error: "
);
throwable
.
printStackTrace
();
}
}
private
static
void
reportOptionalMessage
(
final
Throwable
throwable
)
{
final
String
message
=
throwable
.
getMessage
();
System
.
err
.
println
((
message
!=
null
)
?
": "
+
message
:
""
);
}
public
static
void
workerDone
(
final
long
instrTime
)
{
instrumentationTime
.
addAndGet
(
instrTime
);
if
(
aliveWorkers
.
decrementAndGet
()
==
0
)
{
if
(
timeStat
)
{
System
.
out
.
printf
(
"DiSL: instrumentation took %d milliseconds\n"
,
instrumentationTime
.
get
()
/
1000000
);
}
// no workers - shutdown
if
(!
continuous
)
{
disl
.
terminate
();
if
(
debug
)
{
System
.
out
.
println
(
"DiSL: shutting down instrumentation server..."
);
}
System
.
exit
(
0
);
}
}
}
}
src/ch/usi/dag/dislserver/DiSLServerException.java
View file @
2cfae3b5
...
...
@@ -2,21 +2,21 @@ package ch.usi.dag.dislserver;
public
class
DiSLServerException
extends
Exception
{
private
static
final
long
serialVersionUID
=
5272000884539359236L
;
private
static
final
long
serialVersionUID
=
5272000884539359236L
;
public
DiSLServerException
()
{
super
();
}
public
DiSLServerException
()
{
super
();
}
public
DiSLServerException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
public
DiSLServerException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
public
DiSLServerException
(
String
message
)
{
super
(
message
);
}
public
DiSLServerException
(
String
message
)
{
super
(
message
);
}
public
DiSLServerException
(
Throwable
cause
)
{
super
(
cause
);
}
public
DiSLServerException
(
Throwable
cause
)
{
super
(
cause
);
}
}
src/ch/usi/dag/dislserver/NetMessage.java
View file @
2cfae3b5
package
ch.usi.dag.dislserver
;
public
class
NetMessage
{
private
byte
[]
control
;
private
byte
[]
control
;
private
byte
[]
classCode
;
public
NetMessage
(
byte
[]
control
,
byte
[]
classCode
)
{
...
...
@@ -10,11 +10,11 @@ public class NetMessage {
this
.
classCode
=
classCode
;
}
public
byte
[]
getControl
()
{
return
control
;
}
public
byte
[]
getControl
()
{
return
control
;
}
public
byte
[]
getClassCode
()
{
return
classCode
;
}
public
byte
[]
getClassCode
()
{
return
classCode
;
}
}
src/ch/usi/dag/dislserver/NetMessageReader.java
View file @
2cfae3b5
...
...
@@ -9,59 +9,59 @@ import java.net.Socket;
public
class
NetMessageReader
{
private
final
Socket
socket
;
private
final
DataInputStream
is
;
private
final
DataOutputStream
os
;
public
NetMessageReader
(
Socket
socket
)
throws
IOException
{
this
.
socket
=
socket
;
is
=
new
DataInputStream
(
new
BufferedInputStream
(
socket
.
getInputStream
()));
os
=
new
DataOutputStream
(
new
BufferedOutputStream
(
socket
.
getOutputStream
()));
}
public
NetMessage
readMessage
()
throws
IOException
{
// protocol:
// java int - control string length (ctl)
// java int - class code length (ccl)
// bytes[ctl] - control string (contains class name)
// bytes[ccl] - class code
int
controlLength
=
is
.
readInt
();
int
classCodeLength
=
is
.
readInt
();
// allocate buffer for class reading
byte
[]
control
=
new
byte
[
controlLength
];
byte
[]
classCode
=
new
byte
[
classCodeLength
];
// read class
is
.
readFully
(
control
);
is
.
readFully
(
classCode
);
return
new
NetMessage
(
control
,
classCode
);
}
public
void
close
()
throws
IOException
{
is
.
close
();
socket
.
close
();
}
public
void
sendMessage
(
NetMessage
nm
)
throws
IOException
{
// protocol:
// java int - control string (ctl)
// java int - class code length (ccl)
// bytes[ctl] - control string
// bytes[ccl] - class code
os
.
writeInt
(
nm
.
getControl
().
length
);
os
.
writeInt
(
nm
.
getClassCode
().
length
);
os
.
write
(
nm
.
getControl
());
os
.
write
(
nm
.
getClassCode
());
os
.
flush
();
}
private
final
Socket
socket
;
private
final
DataInputStream
is
;
private
final
DataOutputStream
os
;
public
NetMessageReader
(
Socket
socket
)
throws
IOException
{
this
.
socket
=
socket
;
is
=
new
DataInputStream
(
new
BufferedInputStream
(
socket
.
getInputStream
()));
os
=
new
DataOutputStream
(
new
BufferedOutputStream
(
socket
.
getOutputStream
()));
}
public
NetMessage
readMessage
()
throws
IOException
{
// protocol:
// java int - control string length (ctl)
// java int - class code length (ccl)
// bytes[ctl] - control string (contains class name)
// bytes[ccl] - class code
int
controlLength
=
is
.
readInt
();
int
classCodeLength
=
is
.
readInt
();
// allocate buffer for class reading
byte
[]
control
=
new
byte
[
controlLength
];
byte
[]
classCode
=
new
byte
[
classCodeLength
];
// read class
is
.
readFully
(
control
);
is
.
readFully
(
classCode
);
return
new
NetMessage
(
control
,
classCode
);
}
public
void
close
()
throws
IOException
{
is
.
close
();
socket
.
close
();
}
public
void
sendMessage
(
NetMessage
nm
)
throws
IOException
{
// protocol:
// java int - control string (ctl)
// java int - class code length (ccl)
// bytes[ctl] - control string
// bytes[ccl] - class code
os
.
writeInt
(
nm
.
getControl
().
length
);
os
.
writeInt
(
nm
.
getClassCode
().
length
);
os
.
write
(
nm
.
getControl
());
os
.
write
(
nm
.
getClassCode
());
os
.
flush
();
}
}
src/ch/usi/dag/dislserver/Worker.java
View file @
2cfae3b5
...
...
@@ -15,167 +15,167 @@ import ch.usi.dag.disl.util.Constants;
public
class
Worker
extends
Thread
{
private
static
final
boolean
debug
=
Boolean
.
getBoolean
(
DiSLServer
.
PROP_DEBUG
);
private
static
final
String
PROP_UNINSTR
=
"dislserver.uninstrumented"
;
private
static
final
String
uninstrPath
=
System
.
getProperty
(
PROP_UNINSTR
,
null
);
private
static
final
String
PROP_INSTR
=
"dislserver.instrumented"
;
private
static
final
String
instrPath
=
System
.
getProperty
(
PROP_INSTR
,
null
);
// used for replays
private
static
final
byte
[]
emptyByteArray
=
new
byte
[
0
];
private
final
NetMessageReader
sc
;
private
final
DiSL
disl
;
private
final
AtomicLong
instrumentationTime
=
new
AtomicLong
();
Worker
(
NetMessageReader
sc
,
DiSL
disl
)
{
this
.
sc
=
sc
;
this
.
disl
=
disl
;
}
public
void
run
()
{
try
{
instrumentationLoop
();
sc
.
close
();
}
catch
(
Throwable
e
)
{
DiSLServer
.
reportError
(
e
);
}
finally
{
DiSLServer
.
workerDone
(
instrumentationTime
.
get
());
}
}
private
void
instrumentationLoop
()
throws
Exception
{
try
{
while
(
true
)
{
NetMessage
nm
=
sc
.
readMessage
();
// communication closed by the client
if
(
nm
.
getControl
().
length
==
0
&&
nm
.
getClassCode
().
length
==
0
)
{
return
;
}
byte
[]
instrClass
;
try
{
long
startTime
=
System
.
nanoTime
();
instrClass
=
instrument
(
new
String
(
nm
.
getControl
()),
nm
.
getClassCode
());
instrumentationTime
.
addAndGet
(
System
.
nanoTime
()
-
startTime
);
}
catch
(
Exception
e
)
{
// instrumentation error
// send the client a description of the server-side error
String
errToReport
=
e
.
getMessage
();
// during debug send the whole message
if
(
debug
)
{
StringWriter
sw
=
new
StringWriter
();
e
.
printStackTrace
(
new
PrintWriter
(
sw
));
errToReport
=
sw
.
toString
();
}
// error protocol:
// control contains the description of the server-side error
// class code is an array of size zero
String
errMsg
=
"Instrumentation error for class "
+
new
String
(
nm
.
getControl
())
+
": "
+
errToReport
;
sc
.
sendMessage
(
new
NetMessage
(
errMsg
.
getBytes
(),
emptyByteArray
));
throw
e
;
}
NetMessage
replyData
=
null
;
if
(
instrClass
!=
null
)
{
// class was modified - send modified data
replyData
=
new
NetMessage
(
emptyByteArray
,
instrClass
);
}
else
{
// zero length means no modification
replyData
=
new
NetMessage
(
emptyByteArray
,
emptyByteArray
);
}
sc
.
sendMessage
(
replyData
);
}
}
catch
(
IOException
e
)
{
throw
new
DiSLServerException
(
e
);
}
}
private
byte
[]
instrument
(
String
className
,
byte
[]
origCode
)
throws
DiSLServerException
,
DiSLException
{
// backup for empty class name
if
(
className
==
null
||
className
.
isEmpty
())
{
className
=
UUID
.
randomUUID
().
toString
();
}
// dump uninstrumented
if
(
uninstrPath
!=
null
)
{
dump
(
className
,
origCode
,
uninstrPath
);
}
// instrument