test/hotspot/jtreg/runtime/appcds/jvmti/dumpingWithAgent/libAddToSystemCLSearchOnLoad.c
author ccheung
Fri, 16 Nov 2018 16:10:25 -0800
changeset 52596 dfa02b3f728c
permissions -rw-r--r--
8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping Summary: Allow Java agent during CDS dumping if the AllowArchivingWithJavaAgent dignostic option is specified. Reviewed-by: iklam, jiangli, sspitsyn, dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52596
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
     1
/*
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
     4
 *
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
     8
 *
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    13
 * accompanied this code).
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    14
 *
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    18
 *
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    21
 * questions.
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    22
 */
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    23
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    24
#include <stdio.h>
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    25
#include <string.h>
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    26
#include <jvmti.h>
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    27
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    28
#ifdef __cplusplus
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    29
extern "C" {
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    30
#endif
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    31
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    32
    static jvmtiEnv *jvmti = NULL;
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    33
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    34
    JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) {
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    35
        int err = (*jvm)->GetEnv(jvm, (void**) &jvmti, JVMTI_VERSION_9);
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    36
        if (err != JNI_OK) {
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    37
            return JNI_ERR;
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    38
        }
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    39
        err = (*jvmti)->AddToSystemClassLoaderSearch(jvmti, (const char*)options);
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    40
        if (err != JVMTI_ERROR_NONE) {
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    41
            return JNI_ERR;
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    42
        }
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    43
        return JNI_OK;
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    44
    }
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    45
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    46
#ifdef __cplusplus
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    47
}
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    48
#endif