Commit d9755659 authored by Lubomir Bulej's avatar Lubomir Bulej

Merge branch 'protobuf'

parents a7cc0a2a b2752cd0
Pipeline #3167 passed with stages
in 3 minutes and 4 seconds
......@@ -78,6 +78,7 @@ connection_close (struct connection * connection) {
connection->sockfd, connection->sent_bytes, connection->recv_bytes
);
shutdown (connection->sockfd, SHUT_RDWR);
close (connection->sockfd);
free (connection);
}
......
......@@ -101,8 +101,8 @@ abstract class AbstractParser {
for (final FieldNode field : fields) {
if (field.invisibleAnnotations == null) {
throw new ParserException("DiSL annotation for field "
+ className + "." + field.name + " is missing");
// Ignore fields without annotations.
continue;
}
if (field.invisibleAnnotations.size() > 1) {
......
package ch.usi.dag.disl.classparser;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashMap;
......@@ -32,7 +33,9 @@ import ch.usi.dag.disl.snippet.Snippet;
import ch.usi.dag.disl.snippet.SnippetUnprocessedCode;
import ch.usi.dag.disl.util.AsmHelper;
import ch.usi.dag.disl.util.JavaNames;
import ch.usi.dag.disl.util.Logging;
import ch.usi.dag.disl.util.ReflectionHelper;
import ch.usi.dag.util.logging.Logger;
/**
......@@ -41,6 +44,10 @@ import ch.usi.dag.disl.util.ReflectionHelper;
*/
class SnippetParser extends AbstractParser {
private final Logger __log = Logging.getPackageInstance ();
//
private final List <Snippet> snippets = new LinkedList <> ();
......@@ -60,8 +67,7 @@ class SnippetParser extends AbstractParser {
final String className = AsmHelper.typeName (dislClass);
snippets.addAll (dislClass.methods.parallelStream ().unordered ()
.filter (m -> !JavaNames.isConstructorName (m.name))
.filter (m -> !JavaNames.isInitializerName (m.name))
.filter (m -> __isSnippetCandidate (m))
.map (m -> __parseSnippetWrapper (className, m))
.collect (Collectors.toList ())
);
......@@ -71,6 +77,24 @@ class SnippetParser extends AbstractParser {
}
}
private boolean __isSnippetCandidate (final MethodNode m) {
if (JavaNames.isConstructorName (m.name)) {
__log.trace ("ignoring %s (constructor)", m.name);
return false;
}
if (JavaNames.isInitializerName (m.name)) {
__log.trace ("ignoring %s (static initializer)", m.name);
return false;
}
if (m.invisibleAnnotations == null || m.invisibleAnnotations.isEmpty ()) {
__log.trace ("ignoring %s (no annotations found)", m.name);
return false;
}
return true;
}
private Snippet __parseSnippetWrapper (
final String className, final MethodNode method
......@@ -130,8 +154,7 @@ class SnippetParser extends AbstractParser {
// The ordering of (some of) these checks is important -- some may
// rely on certain assumptions to be satisfied.
//
__ensureSnippetHasAnnotations (method);
__ensureSnippetOnlyHasOneAnnotation (method);
__warnOnMultipleAnnotations (method);
__ensureSnippetOnlyHasDislAnnotations (method);
ensureMethodIsStatic (method);
......@@ -143,20 +166,15 @@ class SnippetParser extends AbstractParser {
ensureMethodUsesContextProperly (method);
}
private static void __ensureSnippetHasAnnotations (
final MethodNode method
) throws SnippetParserException {
if (method.invisibleAnnotations == null) {
throw new SnippetParserException ("no annotations found!");
}
}
private static void __ensureSnippetOnlyHasOneAnnotation (
private void __warnOnMultipleAnnotations (
final MethodNode method
) throws SnippetParserException {
if (method.invisibleAnnotations.size () > 1) {
throw new SnippetParserException ("only one annotation allowed!");
final int annotationCount = method.invisibleAnnotations.size ();
if (annotationCount > 1) {
__log.warn (
"%s has %d annotations, one the first will apply",
method.name, annotationCount
);
}
}
......
......@@ -25,6 +25,10 @@ public class InsnNodeMarker extends AbstractInsnMarker {
classes = new HashSet<Class<? extends AbstractInsnNode>>();
// set delimiter for list of *InsnNode classes
param.setMultipleValDelim (",");
// translate all instructions to opcodes
for (String className : param.getMultipleValues()) {
......
package ch.usi.dag.disl.marker;
/**
* <p>
* Used for marker parameter parsing.
*/
public class Parameter {
public final class Parameter {
protected String value;
protected String __value;
protected String delim;
protected String __delimiter;
/**
* Create parameter with a value.
*/
public Parameter(String value) {
this.value = value;
public Parameter(final String value) {
__value = value;
}
/**
* Set delimiter for multi-value parsing.
*/
public void setMultipleValDelim(String delim) {
this.delim = delim;
public void setMultipleValDelim(final String delim) {
__delimiter = delim;
}
/**
* Get parameter value.
*/
public String getValue() {
return value;
return __value;
}
/**
* Get array of values split according to the set delimiter.
* @return Array of values split using a predefined delimiter.
*/
public String[] getMultipleValues() {
return value.split(delim);
public String [] getMultipleValues () {
return __value.split (__delimiter);
}
}
package ch.usi.dag.disl.resolver;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import ch.usi.dag.disl.exception.GuardException;
/**
* Note that all methods accessing and working with singleton has to be
* thread-safe.
* Note that all methods accessing and working with the {@link GuardResolver}
* singleton have to be thread-safe.
*/
public class GuardResolver {
private static GuardResolver instance = null;
// TODO LB: Get rid of guard resolver singleton
private static GuardResolver instance = new GuardResolver ();
// Guard to guard method map
private Map<Class<?>, GuardMethod> guardToMethod =
new HashMap<Class<?>, GuardMethod>();
public static GuardResolver getInstance () {
return instance;
}
public synchronized GuardMethod getGuardMethod(
Class<?> guardClass) throws GuardException {
//
GuardMethod guardMethod = guardToMethod.get(guardClass);
/** A cache of guard methods corresponding to guard classes. */
private final Map <Class <?>, GuardMethod> __guardMethodsByClass = new HashMap <> ();
// resolved from cache
if(guardMethod != null) {
return guardMethod;
}
// no cache hit
public synchronized GuardMethod getGuardMethod (
final Class <?> guardClass
) throws GuardException {
//
// Try to find the guard method by consulting the cache of methods
// corresponding to guard classes. If it does not provide an answer,
// search of a guard method within the class.
//
final GuardMethod cachedResult = __guardMethodsByClass.get (guardClass);
if (cachedResult != null) {
return cachedResult;
}
// check all methods
for(Method method : guardClass.getMethods()) {
return __findGuardMethod (guardClass);
}
if(method.isAnnotationPresent(
ch.usi.dag.disl.annotation.GuardMethod.class)) {
// detect multiple annotations
if(guardMethod != null) {
throw new GuardException("Detected several "
+ GuardMethod.class.getName()
+ " annotations on guard class "
+ guardClass.getName());
}
private GuardMethod __findGuardMethod (
final Class <?> guardClass
) throws GuardException {
final List <Method> candidateMethods = Arrays.stream (guardClass.getDeclaredMethods ())
.filter (m -> __isGuardMethodCandidate (m))
.collect (Collectors.toList ());
guardMethod = new GuardMethod(method);
}
if (candidateMethods.isEmpty ()) {
throw new GuardException (String.format (
"No method annotated using %s found in class %s",
ch.usi.dag.disl.annotation.GuardMethod.class.getName(),
guardClass.getName()
));
}
// detect no annotation
if(guardMethod == null) {
throw new GuardException("No "
+ ch.usi.dag.disl.annotation.GuardMethod.class.getName()
+ " annotation on some public method in guard class "
+ guardClass.getName());
if (candidateMethods.size () > 1) {
throw new GuardException (String.format (
"Multiple (%d) guard methods found in class %s",
candidateMethods.size (), guardClass.getName()
));
}
// make the method accessible and put it into cache
guardMethod.getMethod ().setAccessible (true);
guardToMethod.put(guardClass, guardMethod);
// Now just get the first method and make it accessible
final Method method = candidateMethods.get (0);
method.setAccessible (true);
return guardMethod;
final GuardMethod result = new GuardMethod (method);
__guardMethodsByClass.put (guardClass, result);
return result;
}
public static synchronized GuardResolver getInstance() {
if (instance == null) {
instance = new GuardResolver();
}
return instance;
private boolean __isGuardMethodCandidate (final Method m) {
return m.isAnnotationPresent(
ch.usi.dag.disl.annotation.GuardMethod.class
);
}
}
......@@ -90,6 +90,23 @@ public class InvocationStaticContext extends AbstractStaticContext {
//
/**
* @return The type name of the class owning the method being invoked, i.e.,
* a fully qualified class name, with packages delimited by the '.'
* character.
*/
public String getOwnerName () {
return JavaNames.internalToType (__methodOwner ());
}
/**
* @return The simple name of the class owning the method being invoked,
* i.e., a class name without the package part of the name.
*/
public String getOwnerSimpleName () {
return JavaNames.simpleClassName (__methodOwner ());
}
/**
* @return The internal name of the class owning the method being invoked.
*/
......
......@@ -1137,6 +1137,7 @@ static void close_connection(int conn, jlong thread_id) {
_buffs_release(buffs);
// close socket
shutdown(conn, SHUT_RDWR);
close(conn);
}
static void * send_thread_loop(void * obj) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment