--- old/test/hotspot/jtreg/testlibrary/jvmti/libSimpleClassFileLoadHook.c 2018-10-21 22:34:20.845014946 -0700 +++ new/test/hotspot/jtreg/testlibrary/jvmti/libSimpleClassFileLoadHook.c 2018-10-21 22:34:20.565004262 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -91,17 +91,23 @@ *new_class_data_len = class_data_len; *new_class_data = new_data; - fprintf(stderr, "Rewriting done. Replaced %d occurrence(s)\n", count); + fprintf(stderr, "Rewriting done. Replaced %d occurrence(s) of \"%s\" to \"%s\"\n", count, FROM, TO); } } } +static int early = 0; + static jint init_options(char *options) { char* class_name; char* from; char* to; fprintf(stderr, "Agent library loaded with options = %s\n", options); + if (options != NULL && strncmp(options, "-early,", 7) == 0) { + early = 1; + options += 7; + } if ((class_name = options) != NULL && (from = strchr(class_name, ',')) != NULL && (from[1] != 0)) { *from = 0; @@ -132,6 +138,7 @@ static jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { int rc; + jvmtiCapabilities caps; if ((rc = (*jvm)->GetEnv(jvm, (void **)&jvmti, JVMTI_VERSION_1_1)) != JNI_OK) { fprintf(stderr, "Unable to create jvmtiEnv, GetEnv failed, error = %d\n", rc); @@ -141,6 +148,19 @@ return JNI_ERR; } + memset(&caps, 0, sizeof(caps)); + + caps.can_redefine_classes = 1; + if (early) { + fprintf(stderr, "can_generate_all_class_hook_events/can_generate_early_vmstart/can_generate_early_class_hook_events == 1\n"); + caps.can_generate_all_class_hook_events = 1; + caps.can_generate_early_class_hook_events = 1; + } + if ((rc = (*jvmti)->AddCapabilities(jvmti, &caps)) != JNI_OK) { + fprintf(stderr, "AddCapabilities failed, error = %d\n", rc); + return JNI_ERR; + } + (void) memset(&callbacks, 0, sizeof(callbacks)); callbacks.ClassFileLoadHook = &ClassFileLoadHook; if ((rc = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks))) != JNI_OK) {