Commit dab55786 authored by Lubomir Bulej's avatar Lubomir Bulej
Browse files

Merge branch 'pre-java9-cleanup' into 'master'

Java 9 cleanups compatible with Java 8

See merge request !12
parents c34d7ce8 45ae8134
Pipeline #7178 passed with stages
in 3 minutes and 31 seconds
......@@ -15,6 +15,6 @@
<classpathentry kind="lib" path="lib/disl/asm-analysis.jar" sourcepath="lib/devel/asm-analysis-source.jar"/>
<classpathentry kind="lib" path="lib/disl/asm-commons.jar" sourcepath="lib/devel/asm-commons-source.jar"/>
<classpathentry kind="lib" path="lib/disl/asm-util.jar" sourcepath="lib/devel/asm-util-source.jar"/>
<classpathentry kind="lib" path="lib/disl/protobuf-lite.jar"/>
<classpathentry kind="lib" path="lib/disl/protobuf-javalite.jar"/>
<classpathentry kind="output" path="output/build/disl"/>
</classpath>
......@@ -35,6 +35,7 @@ build.shvm=${build.dir}/shvm
build.shvm.dispatch=${build.shvm}-dispatch
build.test=${build.dir}/test
build.doc.intro=${build.dir}/intro
build.disl.native=${build.dir}/native
# Build system libraries
build.ivy.url = http://central.maven.org/maven2/org/apache/ivy/ivy/${ivy.rev}/ivy-${ivy.rev}.jar
......
......@@ -513,7 +513,7 @@
<!--
The DiSL agent requires a header file containing flags for
various code generation options. This target generates the
header using "javah" after compiling DiSL.
header using "javac -h" after compiling DiSL.
-->
<target name="-check-disl-agent-codeflags">
<property name="build.disl.agent.codeflags.path" value="${src.disl.agent}/codeflags.h"/>
......@@ -527,13 +527,25 @@
</target>
<target name="-generate-disl-agent-codeflags" depends="compile-disl">
<local name="flags.class"/>
<find-class property="flags.class" dir="${build.disl}" name="*CodeOption$Flag"/>
<delete dir="${build.disl.native}" />
<mkdir dir="${build.disl.native}" />
<javah outputFile="${build.disl.agent.codeflags.path}" force="yes">
<class name="${flags.class}"/>
<classpath refid="disl.classpath"/>
</javah>
<javac srcdir="${src.disl}" destdir="${build.disl.native}" nativeheaderdir="${build.disl.native}" debug="false" includeantruntime="false">
<include name="**/DiSL.java"/>
<classpath>
<path refid="disl.classpath"/>
<path refid="disl.bypass.classpath"/>
<path refid="util.classpath"/>
<path refid="asm.classpath"/>
<path refid="protobuf.classpath"/>
</classpath>
</javac>
<concat destfile="${build.disl.agent.codeflags.path}">
<fileset file="${build.disl.native}/*.h" />
</concat>
<delete dir="${build.disl.native}"/>
</target>
......
......@@ -12,6 +12,6 @@ asm.org=org.ow2.asm
log4j.rev=1.2.17
log4j.org=log4j
protobuf.rev=3.0.1
protobuf.rev=3.11.0
protobuf.org=com.google.protobuf
protobuf.lib=protobuf-lite
protobuf.lib=protobuf-javalite
......@@ -6,6 +6,6 @@ lib/disl/asm-tree.jar
lib/disl/asm-util.jar
lib/disl/asm.jar
lib/disl/log4j.jar
lib/disl/protobuf-lite.jar
lib/disl/protobuf-javalite.jar
lib/test/hamcrest-core.jar
lib/test/junit.jar
......@@ -219,10 +219,8 @@ __instrument_class (
// connection again.
//
InstrumentClassRequest request = INSTRUMENT_CLASS_REQUEST__INIT;
request.has_flags = true;
request.flags = request_flags;
request.classname = (char *) class_name;
request.has_classbytes = true;
request.classbytes.len = class_def->class_byte_count;
request.classbytes.data = (uint8_t *) class_def->class_bytes;
......@@ -266,7 +264,6 @@ __instrument_class (
class_def->class_byte_count = response->classbytes.len;
class_def->class_bytes = response->classbytes.data;
response->has_classbytes = false;
response->classbytes.len = 0;
response->classbytes.data = NULL;
......
......@@ -10,7 +10,7 @@
void instrument_class_request__init
(InstrumentClassRequest *message)
{
static InstrumentClassRequest init_value = INSTRUMENT_CLASS_REQUEST__INIT;
static const InstrumentClassRequest init_value = INSTRUMENT_CLASS_REQUEST__INIT;
*message = init_value;
}
size_t instrument_class_request__get_packed_size
......@@ -47,13 +47,15 @@ void instrument_class_request__free_unpacked
(InstrumentClassRequest *message,
ProtobufCAllocator *allocator)
{
if(!message)
return;
assert(message->base.descriptor == &instrument_class_request__descriptor);
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void instrument_class_response__init
(InstrumentClassResponse *message)
{
static InstrumentClassResponse init_value = INSTRUMENT_CLASS_RESPONSE__INIT;
static const InstrumentClassResponse init_value = INSTRUMENT_CLASS_RESPONSE__INIT;
*message = init_value;
}
size_t instrument_class_response__get_packed_size
......@@ -90,6 +92,8 @@ void instrument_class_response__free_unpacked
(InstrumentClassResponse *message,
ProtobufCAllocator *allocator)
{
if(!message)
return;
assert(message->base.descriptor == &instrument_class_response__descriptor);
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
......@@ -98,9 +102,9 @@ static const ProtobufCFieldDescriptor instrument_class_request__field_descriptor
{
"flags",
1,
PROTOBUF_C_LABEL_OPTIONAL,
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_INT32,
offsetof(InstrumentClassRequest, has_flags),
0, /* quantifier_offset */
offsetof(InstrumentClassRequest, flags),
NULL,
NULL,
......@@ -110,21 +114,21 @@ static const ProtobufCFieldDescriptor instrument_class_request__field_descriptor
{
"className",
2,
PROTOBUF_C_LABEL_OPTIONAL,
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_STRING,
0, /* quantifier_offset */
offsetof(InstrumentClassRequest, classname),
NULL,
NULL,
&protobuf_c_empty_string,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"classBytes",
3,
PROTOBUF_C_LABEL_OPTIONAL,
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_BYTES,
offsetof(InstrumentClassRequest, has_classbytes),
0, /* quantifier_offset */
offsetof(InstrumentClassRequest, classbytes),
NULL,
NULL,
......@@ -162,9 +166,9 @@ static const ProtobufCFieldDescriptor instrument_class_response__field_descripto
{
"result",
1,
PROTOBUF_C_LABEL_OPTIONAL,
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_ENUM,
offsetof(InstrumentClassResponse, has_result),
0, /* quantifier_offset */
offsetof(InstrumentClassResponse, result),
&instrument_class_result__descriptor,
NULL,
......@@ -174,21 +178,21 @@ static const ProtobufCFieldDescriptor instrument_class_response__field_descripto
{
"errorMessage",
2,
PROTOBUF_C_LABEL_OPTIONAL,
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_STRING,
0, /* quantifier_offset */
offsetof(InstrumentClassResponse, errormessage),
NULL,
NULL,
&protobuf_c_empty_string,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"classBytes",
3,
PROTOBUF_C_LABEL_OPTIONAL,
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_BYTES,
offsetof(InstrumentClassResponse, has_classbytes),
0, /* quantifier_offset */
offsetof(InstrumentClassResponse, classbytes),
NULL,
NULL,
......
......@@ -8,9 +8,9 @@
PROTOBUF_C__BEGIN_DECLS
#if PROTOBUF_C_VERSION_NUMBER < 1000000
#if PROTOBUF_C_VERSION_NUMBER < 1003000
# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers.
#elif 1002001 < PROTOBUF_C_MIN_COMPILER_VERSION
#elif 1003002 < PROTOBUF_C_MIN_COMPILER_VERSION
# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c.
#endif
......@@ -33,29 +33,25 @@ typedef enum _InstrumentClassResult {
struct _InstrumentClassRequest
{
ProtobufCMessage base;
protobuf_c_boolean has_flags;
int32_t flags;
char *classname;
protobuf_c_boolean has_classbytes;
ProtobufCBinaryData classbytes;
};
#define INSTRUMENT_CLASS_REQUEST__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&instrument_class_request__descriptor) \
, 0,0, NULL, 0,{0,NULL} }
, 0, (char *)protobuf_c_empty_string, {0,NULL} }
struct _InstrumentClassResponse
{
ProtobufCMessage base;
protobuf_c_boolean has_result;
InstrumentClassResult result;
char *errormessage;
protobuf_c_boolean has_classbytes;
ProtobufCBinaryData classbytes;
};
#define INSTRUMENT_CLASS_RESPONSE__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&instrument_class_response__descriptor) \
, 0,0, NULL, 0,{0,NULL} }
, INSTRUMENT_CLASS_RESULT__CLASS_UNMODIFIED, (char *)protobuf_c_empty_string, {0,NULL} }
/* InstrumentClassRequest methods */
......
......@@ -2072,6 +2072,11 @@ parse_tag_and_wiretype(size_t len,
unsigned shift = 4;
unsigned rv;
/* 0 is not a valid tag value */
if ((data[0] & 0xf8) == 0) {
return 0;
}
*wiretype_out = data[0] & 7;
if ((data[0] & 0x80) == 0) {
*tag_out = tag;
......@@ -2103,18 +2108,18 @@ struct _ScannedMember {
const uint8_t *data; /**< Pointer to field data. */
};
static inline uint32_t
static inline size_t
scan_length_prefixed_data(size_t len, const uint8_t *data,
size_t *prefix_len_out)
{
unsigned hdr_max = len < 5 ? len : 5;
unsigned hdr_len;
uint32_t val = 0;
size_t val = 0;
unsigned i;
unsigned shift = 0;
for (i = 0; i < hdr_max; i++) {
val |= (data[i] & 0x7f) << shift;
val |= ((size_t)data[i] & 0x7f) << shift;
shift += 7;
if ((data[i] & 0x80) == 0)
break;
......@@ -2125,8 +2130,15 @@ scan_length_prefixed_data(size_t len, const uint8_t *data,
}
hdr_len = i + 1;
*prefix_len_out = hdr_len;
if (val > INT_MAX) {
// Protobuf messages should always be less than 2 GiB in size.
// We also want to return early here so that hdr_len + val does
// not overflow on 32-bit systems.
PROTOBUF_C_UNPACK_ERROR("length prefix of %lu is too large", val);
return 0;
}
if (hdr_len + val > len) {
PROTOBUF_C_UNPACK_ERROR("data too short after length-prefix of %u", val);
PROTOBUF_C_UNPACK_ERROR("data too short after length-prefix of %lu", val);
return 0;
}
return hdr_len + val;
......@@ -2239,6 +2251,8 @@ merge_messages(ProtobufCMessage *earlier_msg,
latter_msg->descriptor
->field_ranges,
*earlier_case_p);
if (field_index < 0)
return FALSE;
field = latter_msg->descriptor->fields +
field_index;
} else {
......@@ -2627,14 +2641,17 @@ parse_oneof_member (ScannedMember *scanned_member,
/* If we have already parsed a member of this oneof, free it. */
if (*oneof_case != 0) {
const ProtobufCFieldDescriptor *old_field;
size_t el_size;
/* lookup field */
int field_index =
int_range_lookup(message->descriptor->n_field_ranges,
message->descriptor->field_ranges,
*oneof_case);
const ProtobufCFieldDescriptor *old_field =
message->descriptor->fields + field_index;
size_t el_size = sizeof_elt_in_repeated_array(old_field->type);
if (field_index < 0)
return FALSE;
old_field = message->descriptor->fields + field_index;
el_size = sizeof_elt_in_repeated_array(old_field->type);
switch (old_field->type) {
case PROTOBUF_C_TYPE_STRING: {
......@@ -3411,6 +3428,13 @@ protobuf_c_message_check(const ProtobufCMessage *message)
ProtobufCLabel label = f->label;
void *field = STRUCT_MEMBER_P (message, f->offset);
if (f->flags & PROTOBUF_C_FIELD_FLAG_ONEOF) {
const uint32_t *oneof_case = STRUCT_MEMBER_P (message, f->quantifier_offset);
if (f->id != *oneof_case) {
continue; //Do not check if it is an unpopulated oneof member.
}
}
if (label == PROTOBUF_C_LABEL_REPEATED) {
size_t *quantity = STRUCT_MEMBER_P (message, f->quantifier_offset);
......@@ -3639,4 +3663,4 @@ protobuf_c_service_descriptor_get_method_by_name(const ProtobufCServiceDescripto
if (strcmp(desc->methods[desc->method_indices_by_name[start]].name, name) == 0)
return desc->methods + desc->method_indices_by_name[start];
return NULL;
}
}
\ No newline at end of file
/*
* Copyright (c) 2008-2017, Dave Benson and the protobuf-c authors.
* Copyright (c) 2008-2018, Dave Benson and the protobuf-c authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......@@ -790,13 +790,13 @@ protobuf_c_version_number(void);
* The version of the protobuf-c headers, represented as a string using the same
* format as protobuf_c_version().
*/
#define PROTOBUF_C_VERSION "1.3.0"
#define PROTOBUF_C_VERSION "1.3.2"
/**
* The version of the protobuf-c headers, represented as an integer using the
* same format as protobuf_c_version_number().
*/
#define PROTOBUF_C_VERSION_NUMBER 1003000
#define PROTOBUF_C_VERSION_NUMBER 1003002
/**
* The minimum protoc-c version which works with the current version of the
......@@ -1103,4 +1103,4 @@ protobuf_c_service_invoke_internal(
PROTOBUF_C__END_DECLS
#endif /* PROTOBUF_C_H */
#endif /* PROTOBUF_C_H */
\ No newline at end of file
......@@ -2,6 +2,7 @@ package ch.usi.dag.disl;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.annotation.Native;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap;
......@@ -429,7 +430,7 @@ public final class DiSL {
if (!tlvs.isEmpty ()) {
// instrument fields
final ClassNode cnWithFields = new ClassNode (Opcodes.ASM5);
final ClassNode cnWithFields = new ClassNode (Opcodes.ASM7);
classNode.accept (new TLVInserter (cnWithFields, tlvs));
// replace original code with instrumented one
......@@ -586,9 +587,13 @@ public final class DiSL {
* used when communicating with DiSL agent.
*/
public interface Flag {
@Native
static final int CREATE_BYPASS = 1 << 0;
@Native
static final int DYNAMIC_BYPASS = 1 << 1;
@Native
static final int SPLIT_METHODS = 1 << 2;
@Native
static final int CATCH_EXCEPTIONS = 1 << 3;
}
......
......@@ -30,7 +30,7 @@ final class TLVInserter extends ClassVisitor {
//
public TLVInserter (final ClassVisitor cv, final Set <ThreadLocalVar> tlvs) {
super (Opcodes.ASM5, cv);
super (Opcodes.ASM7, cv);
__threadLocals = tlvs;
}
......@@ -97,7 +97,7 @@ final class TLVInserter extends ClassVisitor {
final MethodVisitor mv,
final int access, final String name, final String desc
) {
super (Opcodes.ASM5, mv, access, name, desc);
super (Opcodes.ASM7, mv, access, name, desc);
assert JavaNames.isConstructorName (name);
}
......
......@@ -110,7 +110,7 @@ final class AnnotationMapper {
Predicate <String>, BiConsumer <String, Object>
> consumers = __findConsumers (ac);
an.accept (new AnnotationVisitor (Opcodes.ASM5) {
an.accept (new AnnotationVisitor (Opcodes.ASM7) {
@Override
public void visit (final String name, final Object value) {
__getConsumer (consumers, name).accept (name, value);
......@@ -149,7 +149,7 @@ final class AnnotationMapper {
final BiConsumer <String, Object> __consumer;
ListCollector (final String name, final BiConsumer <String, Object> consumer) {
super (Opcodes.ASM5);
super (Opcodes.ASM7);
__name = name;
__consumer = consumer;
......
......@@ -76,7 +76,7 @@ public class AfterInitBodyMarker extends AbstractMarker {
//
final AtomicBoolean superInitialized = new AtomicBoolean (false);
final AdviceAdapter adapter = new AdviceAdapter (
Opcodes.ASM5, new MethodVisitor (Opcodes.ASM5) { /* empty */ },
Opcodes.ASM7, new MethodVisitor (Opcodes.ASM7) { /* empty */ },
method.access, method.name, method.desc
) {
@Override
......
......@@ -470,7 +470,7 @@ public abstract class AsmHelper {
*/
public static MethodNode cloneMethod (final MethodNode method) {
final MethodNode result = new MethodNode (
Opcodes.ASM5, method.access, method.name, method.desc,
Opcodes.ASM7, method.access, method.name, method.desc,
method.signature, method.exceptions.toArray (
new String [method.exceptions.size ()]
)
......
......@@ -17,7 +17,7 @@ import org.objectweb.asm.tree.analysis.Interpreter;
public class ConstInterpreter extends Interpreter<ConstValue> {
protected ConstInterpreter() {
super(Opcodes.ASM5);
super(Opcodes.ASM7);
}
@Override
......
......@@ -64,7 +64,7 @@ public class TargetClass {
sendThread (false, thread);
// Send a lot of empty events to force the agent to flush buffers.
for (int i = 0; i < 35000; i++) {
for (int i = 0; i < 100000; i++) {
sendEmpty ();
}
......
......@@ -14,6 +14,7 @@ import java.util.stream.Stream;
import org.junit.Assert;
import org.junit.experimental.theories.PotentialAssignment;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.ClassNode;
......@@ -33,6 +34,18 @@ abstract class ShadowClassTestBase {
protected abstract ShadowClass _createShadowClass (final Class <?> type);
/**
* Removes ASM specific access flags not defined in the
* JVM specification. This is necessary to compare regular and
* shadow info.
*
* JVM access flags are stored using 16 bits only, so it is just
* possible to apply a mask.
*/
private int removeASMSpecificAccessFlags(int modifiers) {
return modifiers & 65535;
}
//
void getNameMatchesReflection (final Class <?> type) {
......@@ -171,7 +184,7 @@ abstract class ShadowClassTestBase {
private void __assertEquals (final Field field, final FieldInfo shadowField) {
Assert.assertEquals (field.getName (), shadowField.getName ());
Assert.assertEquals (Type.getType (field.getType ()).getDescriptor (), shadowField.getDescriptor ());
Assert.assertEquals (field.getModifiers (), shadowField.getModifiers ());
Assert.assertEquals (field.getModifiers (), removeASMSpecificAccessFlags(shadowField.getModifiers ()));
}
//
......@@ -233,7 +246,7 @@ abstract class ShadowClassTestBase {
private void __assertEqual (final Method method, final MethodInfo shadowMethod) {
Assert.assertEquals (method.getName (), shadowMethod.getName ());
Assert.assertEquals (Type.getMethodDescriptor (method), shadowMethod.getDescriptor ());
Assert.assertEquals (method.getModifiers (), shadowMethod.getModifiers ());
Assert.assertEquals (method.getModifiers (), removeASMSpecificAccessFlags(shadowMethod.getModifiers ()));
}
//
......
......@@ -60,7 +60,7 @@ public final class ExtendThread {
private Type __owner;
public FieldExtender (final FieldDefinition fd, final ClassWriter cw) {
super (Opcodes.ASM5, cw);
super (Opcodes.ASM7, cw);
__fd = fd;
}
......@@ -86,7 +86,7 @@ public final class ExtendThread {
if ("<init>".equals (name)) {
// Initialize the field.
return new AdviceAdapter (Opcodes.ASM5, mv, access, name, desc) {
return new AdviceAdapter (Opcodes.ASM7, mv, access, name, desc) {
@Override
protected void onMethodEnter () {
__fd.initialize (__owner, this);
......@@ -150,7 +150,7 @@ public final class ExtendThread {
throws IOException {
final ClassReader cr = new ClassReader (Thread.class.getName ());
final ClassWriter cw = new ClassWriter (cr, 0);
cr.accept (new FieldExtender (fd, cw), 0);
cr.accept (new FieldExtender (fd, cw), ClassReader.EXPAND_FRAMES);
return cw.toByteArray ();
}
......
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