Commit ce6bbcb0 authored by Lukáš Marek's avatar Lukáš Marek

floats and doubles are buffered in native code

parent 2960b3b9
......@@ -15,10 +15,29 @@
#include <endian.h>
// GCC has known bug where it does not work always correctly
#ifndef __STDC_IEC_559__
#error "Requires IEEE 754 floating point!"
#include "../src-agent-c/jvmtihelper.h"
#include "buffer.h"
// interpret bytes differently
union float_jint {
float f;
jint i;
// interpret bytes differently
union double_jlong {
double d;
jlong l;
void pack_boolean(buffer * buff, jboolean to_send) {
buffer_fill(buff, &to_send, sizeof(jboolean));
......@@ -47,6 +66,22 @@ void pack_long(buffer * buff, jlong to_send) {
buffer_fill(buff, &nts, sizeof(jlong));
void pack_float(buffer * buff, jfloat to_send) {
// macro ensures that the formating of the float is correct
// so make "int" from it and send it
union float_jint convert;
convert.f = to_send;
pack_int(buff, convert.i);
void pack_double(buffer * buff, jdouble to_send) {
// macro ensures that the formating of the double is correct
// so make "long" from it and send it
union double_jlong convert;
convert.d = to_send;
pack_long(buff, convert.l);
void pack_string_utf8(buffer * buff, const void * string_utf8,
uint16_t size_in_bytes) {
......@@ -1793,16 +1793,16 @@ JNIEXPORT void JNICALL Java_ch_usi_dag_dislre_REDispatch_sendLong
pack_long(tld_get()->analysis_buff, to_send);
JNIEXPORT void JNICALL Java_ch_usi_dag_dislre_REDispatch_sendFloatAsInt
(JNIEnv * jni_env, jclass this_class, jint to_send) {
JNIEXPORT void JNICALL Java_ch_usi_dag_dislre_REDispatch_sendFloat
(JNIEnv * jni_env, jclass this_class, jfloat to_send) {
pack_int(tld_get()->analysis_buff, to_send);
pack_float(tld_get()->analysis_buff, to_send);
JNIEXPORT void JNICALL Java_ch_usi_dag_dislre_REDispatch_sendDoubleAsLong
(JNIEnv * jni_env, jclass this_class, jlong to_send) {
JNIEXPORT void JNICALL Java_ch_usi_dag_dislre_REDispatch_sendDouble
(JNIEnv * jni_env, jclass this_class, jdouble to_send) {
pack_long(tld_get()->analysis_buff, to_send);
pack_double(tld_get()->analysis_buff, to_send);
JNIEXPORT void JNICALL Java_ch_usi_dag_dislre_REDispatch_sendObject
......@@ -40,27 +40,17 @@ public class REDispatch {
public static native void sendShort(short shortToSend);
public static native void sendInt(int intToSend);
public static native void sendLong(long longToSend);
public static native void sendFloatAsInt(int floatAsIntToSend);
public static native void sendDoubleAsLong(long doubleAsLongToSend);
public static native void sendObject(Object objToSend);
public static native void sendObjectPlusData(Object objToSend);
// helper methods for sending float and double
// for proper conversion, we would still need to call ...Bits methods
// it is faster to call them here then call it from native code
// faster would be to do it native code all - be my guest :)
public static void sendFloat(float floatToSend) {
// helper method for sending double
public static void sendDouble(double doubleToSend) {
// Methods use similar logic as Float.floatToIntBits() and
// Double.doubleToLongBits() but implemented in the native code
// to avoid perturbation
public static native void sendFloat(float floatToSend);
public static native void sendDouble(double doubleToSend);
// TODO re - basic type array support
// - send length + all values in for cycle
// - send length + all values in for cycle - all in native code
// PROBLEM: somebody can change the values from the outside
// - for example different thread
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment