< prev index next >

test/hotspot/jtreg/serviceability/jvmti/HiddenClass/libHiddenClassSigTest.cpp

Print this page

 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 #include <string.h>
 25 #include "jvmti.h"
 26 #include "jvmti_common.hpp"
 27 
 28 extern "C" {
 29 
 30 static const char* EXP_INTERF_SIG = "LP/Q/HCInterf;";
 31 static const char* SIG_START      = "LP/Q/HiddenClassSig";

 32 static const size_t SIG_START_LEN = strlen(SIG_START);
 33 static const int    ACC_INTERFACE = 0x0200; // Interface class modifiers bit
 34 
 35 static jvmtiEnv *jvmti = nullptr;
 36 static jint class_load_count = 0;
 37 static jint class_prep_count = 0;
 38 static bool failed = false;
 39 // JVMTI_ERROR_WRONG_PHASE guard
 40 static jrawMonitorID event_mon = nullptr;
 41 static bool is_vm_dead = false;
 42 
 43 #define LOG0(str)             { printf(str); fflush(stdout); }
 44 #define LOG1(str, arg)        { printf(str, arg); fflush(stdout); }
 45 #define LOG2(str, arg1, arg2) { printf(str, arg1, arg2); fflush(stdout); }
 46 
 47 #define CHECK_JVMTI_ERROR(jni, err, msg) \
 48   if (err != JVMTI_ERROR_NONE) { \
 49     LOG1("CHECK_JVMTI_ERROR: JVMTI function returned error: %d\n", err); \
 50     jni->FatalError(msg); \
 51     return; \

179     }
180     // get class signature
181     err = jvmti->GetClassSignature(kls, &sig, nullptr);
182     CHECK_JVMTI_ERROR(jni, err, "check_hidden_class_loader: Error in JVMTI GetClassSignature");
183 
184     LOG1("check_hidden_class_loader: FAIL: JVMTI GetClassLoaderClasses returned hidden class: %s\n", sig);
185     failed = true;
186     return;
187   }
188   LOG0("check_hidden_class_loader: not found hidden class in its loader classes as expected\n");
189 }
190 
191 /* Test the hidden class implements expected interface. */
192 static void
193 check_hidden_class_impl_interf(jvmtiEnv* jvmti, JNIEnv* jni, jclass klass) {
194   char* sig = nullptr;
195   jint count = 0;
196   jclass* interfaces = nullptr;
197   jvmtiError err;
198 
199   // check that hidden class implements just one interface
200   err = jvmti->GetImplementedInterfaces(klass, &count, &interfaces);
201   CHECK_JVMTI_ERROR(jni, err, "check_hidden_class_impl_interf: Error in JVMTI GetImplementedInterfaces");
202   if (count != 1) {
203     LOG1("check_hidden_class_impl_interf: FAIL: implemented interfaces count: %d, expected to be 1\n", count);
204     failed = true;
205     return;
206   }
207   // get interface signature
208   err = jvmti->GetClassSignature(interfaces[0], &sig, nullptr);
209   CHECK_JVMTI_ERROR(jni, err, "check_hidden_class_impl_interf: Error in JVMTI GetClassSignature for implemented interface");







210 
211   // check the interface signature is matching the expected
212   if (strcmp(sig, EXP_INTERF_SIG) != 0) {
213     LOG2("check_hidden_class_impl_interf: FAIL: implemented interface signature: %s, expected to be: %s\n",
214            sig, EXP_INTERF_SIG);
215     failed = true;
216   }
217 }
218 
219 /* Test hidden class. */
220 static void
221 check_hidden_class(jvmtiEnv* jvmti, JNIEnv* jni, jclass klass, const char* exp_sig) {
222   char* source_file_name = nullptr;
223 
224   LOG1("\n### Native agent: check_hidden_class started: class: %s\n", exp_sig);
225 
226   check_class_signature(jvmti, jni, klass, true /* not hidden */,  exp_sig);
227   if (failed) return;
228 
229   check_hidden_class_flags(jvmti, jni, klass);
230   if (failed) return;
231 
232   check_hidden_class_loader(jvmti, jni, klass);

 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 #include <string.h>
 25 #include "jvmti.h"
 26 #include "jvmti_common.hpp"
 27 
 28 extern "C" {
 29 
 30 static const char* EXP_INTERF_SIG = "LP/Q/HCInterf;";
 31 static const char* SIG_START      = "LP/Q/HiddenClassSig";
 32 static const char* IDENTITYOBJECT_IF = "Ljava/lang/IdentityObject;";
 33 static const size_t SIG_START_LEN = strlen(SIG_START);
 34 static const int    ACC_INTERFACE = 0x0200; // Interface class modifiers bit
 35 
 36 static jvmtiEnv *jvmti = nullptr;
 37 static jint class_load_count = 0;
 38 static jint class_prep_count = 0;
 39 static bool failed = false;
 40 // JVMTI_ERROR_WRONG_PHASE guard
 41 static jrawMonitorID event_mon = nullptr;
 42 static bool is_vm_dead = false;
 43 
 44 #define LOG0(str)             { printf(str); fflush(stdout); }
 45 #define LOG1(str, arg)        { printf(str, arg); fflush(stdout); }
 46 #define LOG2(str, arg1, arg2) { printf(str, arg1, arg2); fflush(stdout); }
 47 
 48 #define CHECK_JVMTI_ERROR(jni, err, msg) \
 49   if (err != JVMTI_ERROR_NONE) { \
 50     LOG1("CHECK_JVMTI_ERROR: JVMTI function returned error: %d\n", err); \
 51     jni->FatalError(msg); \
 52     return; \

180     }
181     // get class signature
182     err = jvmti->GetClassSignature(kls, &sig, nullptr);
183     CHECK_JVMTI_ERROR(jni, err, "check_hidden_class_loader: Error in JVMTI GetClassSignature");
184 
185     LOG1("check_hidden_class_loader: FAIL: JVMTI GetClassLoaderClasses returned hidden class: %s\n", sig);
186     failed = true;
187     return;
188   }
189   LOG0("check_hidden_class_loader: not found hidden class in its loader classes as expected\n");
190 }
191 
192 /* Test the hidden class implements expected interface. */
193 static void
194 check_hidden_class_impl_interf(jvmtiEnv* jvmti, JNIEnv* jni, jclass klass) {
195   char* sig = nullptr;
196   jint count = 0;
197   jclass* interfaces = nullptr;
198   jvmtiError err;
199 
200   // check that hidden class implements just one interface (or two if IdentityObject has been injected)
201   err = jvmti->GetImplementedInterfaces(klass, &count, &interfaces);
202   CHECK_JVMTI_ERROR(jni, err, "check_hidden_class_impl_interf: Error in JVMTI GetImplementedInterfaces");
203   if (count != 1 && count != 2) {
204     LOG1("check_hidden_class_impl_interf: FAIL: implemented interfaces count: %d, expected to be in [1-2] range\n", count);
205     failed = true;
206     return;
207   }
208   bool found = false;
209   for (int i = 0; i < count; i++) {
210     // get interface signature
211     err = jvmti->GetClassSignature(interfaces[i], &sig, nullptr);
212     CHECK_JVMTI_ERROR(jni, err, "check_hidden_class_impl_interf: Error in JVMTI GetClassSignature for implemented interface");
213     // check the interface signature is matching the expected
214     if (strcmp(sig, EXP_INTERF_SIG) == 0) {
215       found = true;
216     }
217   }
218 
219   if (!found) {

220     LOG2("check_hidden_class_impl_interf: FAIL: implemented interface signature: %s, expected to be: %s\n",
221            sig, EXP_INTERF_SIG);
222     failed = true;
223   }
224 }
225 
226 /* Test hidden class. */
227 static void
228 check_hidden_class(jvmtiEnv* jvmti, JNIEnv* jni, jclass klass, const char* exp_sig) {
229   char* source_file_name = nullptr;
230 
231   LOG1("\n### Native agent: check_hidden_class started: class: %s\n", exp_sig);
232 
233   check_class_signature(jvmti, jni, klass, true /* not hidden */,  exp_sig);
234   if (failed) return;
235 
236   check_hidden_class_flags(jvmti, jni, klass);
237   if (failed) return;
238 
239   check_hidden_class_loader(jvmti, jni, klass);
< prev index next >