diff src/share/vm/utilities/globalDefinitions.hpp @ 20287:b6a8cc1e0d92

8040121: Load variable through a pointer of an incompatible type in src/hotspot/src/share/vm: opto/output.cpp, runtime/sharedRuntimeTrans.cpp, utilities/globalDefinitions_visCPP.hpp Summary: Fixed parfait warnings in globalDefinitions files by using a union for casts. Reviewed-by: kvn
author thartmann
date Tue, 29 Jul 2014 13:54:16 +0200
parents 78bbf4d43a14
children 7848fc12602b
line wrap: on
line diff
--- a/src/share/vm/utilities/globalDefinitions.hpp	Thu May 22 11:36:23 2014 -0400
+++ b/src/share/vm/utilities/globalDefinitions.hpp	Tue Jul 29 13:54:16 2014 +0200
@@ -558,6 +558,27 @@
   return fabs(value);
 }
 
+//----------------------------------------------------------------------------------------------------
+// Special casts
+// Cast floats into same-size integers and vice-versa w/o changing bit-pattern
+typedef union {
+  jfloat f;
+  jint i;
+} FloatIntConv;
+
+typedef union {
+  jdouble d;
+  jlong l;
+  julong ul;
+} DoubleLongConv;
+
+inline jint    jint_cast    (jfloat  x)  { return ((FloatIntConv*)&x)->i; }
+inline jfloat  jfloat_cast  (jint    x)  { return ((FloatIntConv*)&x)->f; }
+
+inline jlong   jlong_cast   (jdouble x)  { return ((DoubleLongConv*)&x)->l;  }
+inline julong  julong_cast  (jdouble x)  { return ((DoubleLongConv*)&x)->ul; }
+inline jdouble jdouble_cast (jlong   x)  { return ((DoubleLongConv*)&x)->d;  }
+
 inline jint low (jlong value)                    { return jint(value); }
 inline jint high(jlong value)                    { return jint(value >> 32); }