Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8263595: Remove oop type punning in JavaCallArguments
Reviewed-by: iklam, coleenp, kbarrett
  • Loading branch information
stefank committed Mar 16, 2021
1 parent a1f6591 commit a31a23d5e72c4618b5b67e854ef4909110a1b5b4
@@ -66,9 +66,8 @@ class JNITypes : AllStatic {
}

// Oops are stored in native format in one JavaCallArgument slot at *to.
static inline void put_obj(oop from, intptr_t *to) { *(oop *)(to + 0 ) = from; }
static inline void put_obj(oop from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = from; }
static inline void put_obj(oop *from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = *from; }
static inline void put_obj(const Handle& from_handle, intptr_t *to, int& pos) { *(to + pos++) = (intptr_t)from_handle.raw_value(); }
static inline void put_obj(jobject from_handle, intptr_t *to, int& pos) { *(to + pos++) = (intptr_t)from_handle; }

// Floats are stored in native format in one JavaCallArgument slot at *to.
static inline void put_float(jfloat from, intptr_t *to) { *(jfloat *)(to + 0 ) = from; }
@@ -62,9 +62,8 @@ class JNITypes : AllStatic {
static inline void put_long(jlong *from, intptr_t *to, int& pos) { put_int2r((jint *) from, to, pos); }

// Oops are stored in native format in one JavaCallArgument slot at *to.
static inline void put_obj(oop from, intptr_t *to) { *(oop *)(to + 0 ) = from; }
static inline void put_obj(oop from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = from; }
static inline void put_obj(oop *from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = *from; }
static inline void put_obj(const Handle& from_handle, intptr_t *to, int& pos) { *(to + pos++) = (intptr_t)from_handle.raw_value(); }
static inline void put_obj(jobject from_handle, intptr_t *to, int& pos) { *(to + pos++) = (intptr_t)from_handle; }

// Floats are stored in native format in one JavaCallArgument slot at *to.
static inline void put_float(jfloat from, intptr_t *to) { *(jfloat *)(to + 0 ) = from; }
@@ -72,9 +72,8 @@ class JNITypes : AllStatic {
}

// Oops are stored in native format in one JavaCallArgument slot at *to.
static inline void put_obj(oop from, intptr_t *to) { *(oop *)(to + 0 ) = from; }
static inline void put_obj(oop from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = from; }
static inline void put_obj(oop *from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = *from; }
static inline void put_obj(const Handle& from_handle, intptr_t *to, int& pos) { *(to + pos++) = (intptr_t)from_handle.raw_value(); }
static inline void put_obj(jobject from_handle, intptr_t *to, int& pos) { *(to + pos++) = (intptr_t)from_handle; }

// Floats are stored in native format in one JavaCallArgument slot at *to.
static inline void put_float(jfloat from, intptr_t *to) { *(jfloat *)(to + 0 ) = from; }
@@ -73,16 +73,12 @@ class JNITypes : AllStatic {
}

// Oops are stored in native format in one JavaCallArgument slot at *to.
static inline void put_obj(oop from, intptr_t *to) {
*(oop*) to = from;
static inline void put_obj(const Handle& from_handle, intptr_t *to, int& pos) {
*(to + pos++) = (intptr_t)from_handle.raw_value();
}

static inline void put_obj(oop from, intptr_t *to, int& pos) {
*(oop*) (to + pos++) = from;
}

static inline void put_obj(oop *from, intptr_t *to, int& pos) {
*(oop*) (to + pos++) = *from;
static inline void put_obj(jobject from_handle, intptr_t *to, int& pos) {
*(to + pos++) = (intptr_t)from_handle;
}

// Floats are stored in native format in one JavaCallArgument slot at *to.
@@ -82,9 +82,8 @@ class JNITypes : AllStatic {
#endif // AMD64

// Oops are stored in native format in one JavaCallArgument slot at *to.
static inline void put_obj(oop from, intptr_t *to) { *(oop *)(to + 0 ) = from; }
static inline void put_obj(oop from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = from; }
static inline void put_obj(oop *from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = *from; }
static inline void put_obj(const Handle& from_handle, intptr_t *to, int& pos) { *(to + pos++) = (intptr_t)from_handle.raw_value(); }
static inline void put_obj(jobject from_handle, intptr_t *to, int& pos) { *(to + pos++) = (intptr_t)from_handle; }

// Floats are stored in native format in one JavaCallArgument slot at *to.
static inline void put_float(jfloat from, intptr_t *to) { *(jfloat *)(to + 0 ) = from; }
@@ -69,9 +69,8 @@ class JNITypes : AllStatic {
#endif

// Oops are stored in native format in one JavaCallArgument slot at *to.
static inline void put_obj(oop from, intptr_t *to) { *(oop *)(to + 0 ) = from; }
static inline void put_obj(oop from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = from; }
static inline void put_obj(oop *from, intptr_t *to, int& pos) { *(oop *)(to + pos++) = *from; }
static inline void put_obj(const Handle& from_handle, intptr_t *to, int& pos) { *(to + pos++) = (intptr_t)from_handle.raw_value(); }
static inline void put_obj(jobject from_handle, intptr_t *to, int& pos) { *(to + pos++) = (intptr_t)from_handle; }

// Floats are stored in native format in one JavaCallArgument slot at *to.
static inline void put_float(jfloat from, intptr_t *to) { *(jfloat *)(to + 0 ) = from; }
@@ -98,7 +98,7 @@ class Handle {

// Raw handle access. Allows easy duplication of Handles. This can be very unsafe
// since duplicates is only valid as long as original handle is alive.
oop* raw_value() { return _handle; }
oop* raw_value() const { return _handle; }
static oop raw_resolve(oop *handle) { return handle == NULL ? (oop)NULL : *handle; }
};

@@ -103,23 +103,6 @@ class JavaCallArguments : public StackObj {
_start_at_zero = false;
}

// Helper for push_oop and the like. The value argument is a
// "handle" that refers to an oop. We record the address of the
// handle rather than the designated oop. The handle is later
// resolved to the oop by parameters(). This delays the exposure of
// naked oops until it is GC-safe.
template<typename T>
inline int push_oop_impl(T handle, int size) {
// JNITypes::put_obj expects an oop value, so we play fast and
// loose with the type system. The cast from handle type to oop
// *must* use a C-style cast. In a product build it performs a
// reinterpret_cast. In a debug build (more accurately, in a
// CHECK_UNHANDLED_OOPS build) it performs a static_cast, invoking
// the debug-only oop class's conversion from void* constructor.
JNITypes::put_obj((oop)handle, _value, size); // Updates size.
return size; // Return the updated size.
}

public:
JavaCallArguments() { initialize(); }

@@ -166,12 +149,12 @@ class JavaCallArguments : public StackObj {

inline void push_oop(Handle h) {
_value_state[_size] = value_state_handle;
_size = push_oop_impl(h.raw_value(), _size);
JNITypes::put_obj(h, _value, _size);
}

inline void push_jobject(jobject h) {
_value_state[_size] = value_state_jobject;
_size = push_oop_impl(h, _size);
JNITypes::put_obj(h, _value, _size);
}

inline void push_int(int i) {
@@ -212,7 +195,9 @@ class JavaCallArguments : public StackObj {
_value--;
_size++;
_value_state[0] = value_state_handle;
push_oop_impl(h.raw_value(), 0);

int size = 0;
JNITypes::put_obj(h, _value, size);
}

// Converts all Handles to oops, and returns a reference to parameter vector

0 comments on commit a31a23d

Please sign in to comment.