< prev index next >

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

Print this page

 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 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 
 27 extern "C" {
 28 
 29 static const char* EXP_INTERF_SIG = "LP/Q/HCInterf;";
 30 static const char* SIG_START      = "LP/Q/HiddenClassSig";

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

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







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

 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 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 
 27 extern "C" {
 28 
 29 static const char* EXP_INTERF_SIG = "LP/Q/HCInterf;";
 30 static const char* SIG_START      = "LP/Q/HiddenClassSig";
 31 static const char* IDENTITYOBJECT_IF = "Ljava/lang/IdentityObject;";
 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 = NULL;
 36 static jint class_load_count = 0;
 37 static jint class_prep_count = 0;
 38 static bool failed = false;
 39 
 40 #define LOG0(str)             { printf(str); fflush(stdout); }
 41 #define LOG1(str, arg)        { printf(str, arg); fflush(stdout); }
 42 #define LOG2(str, arg1, arg2) { printf(str, arg1, arg2); fflush(stdout); }
 43 
 44 #define CHECK_JVMTI_ERROR(jni, err, msg) \
 45   if (err != JVMTI_ERROR_NONE) { \
 46     LOG1("CHECK_JVMTI_ERROR: JVMTI function returned error: %d\n", err); \
 47     jni->FatalError(msg); \
 48     return; \
 49   }
 50 
 51 /* Return the jmethodID of j.l.Class.isHidden() method. */

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

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