--- old/src/jdk.hotspot.agent/linux/native/libsaproc/LinuxDebuggerLocal.c 2018-06-28 21:55:38.541364491 +0900 +++ new/src/jdk.hotspot.agent/linux/native/libsaproc/LinuxDebuggerLocal.c 2018-06-28 21:55:38.344369146 +0900 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 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 @@ -66,6 +66,8 @@ static jmethodID getThreadForThreadId_ID = 0; static jmethodID listAdd_ID = 0; +static char *saaltroot = NULL; + #define CHECK_EXCEPTION_(value) if ((*env)->ExceptionOccurred(env)) { return value; } #define CHECK_EXCEPTION if ((*env)->ExceptionOccurred(env)) { return;} #define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { throw_new_debugger_exception(env, str); return value; } @@ -211,11 +213,34 @@ /* * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal + * Method: setSAAltRoot0 + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_setSAAltRoot0 + (JNIEnv *env, jobject this_obj, jstring altroot) { + if (saaltroot != NULL) { + free(saaltroot); + } + const char *path = (*env)->GetStringUTFChars(env, altroot, JNI_FALSE); + /* + * `saaltroot` is used for putenv(). + * So we need to keep this memory. + */ + static const char *PREFIX = "SA_ALTROOT="; + size_t len = strlen(PREFIX) + strlen(path) + 1; + saaltroot = (char *)malloc(len); + snprintf(saaltroot, len, "%s%s", PREFIX, path); + putenv(saaltroot); + (*env)->ReleaseStringUTFChars(env, altroot, path); +} + +/* + * Class: sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal * Method: attach0 - * Signature: (I)V + * Signature: (IZ)V */ -JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__I - (JNIEnv *env, jobject this_obj, jint jpid) { +JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_attach0__IZ + (JNIEnv *env, jobject this_obj, jint jpid, jboolean is_in_container) { // For bitness checking, locate binary at /proc/jpid/exe char buf[PATH_MAX]; @@ -225,7 +250,7 @@ char err_buf[200]; struct ps_prochandle* ph; - if ( (ph = Pgrab(jpid, err_buf, sizeof(err_buf))) == NULL) { + if ( (ph = Pgrab(jpid, err_buf, sizeof(err_buf), is_in_container)) == NULL) { char msg[230]; snprintf(msg, sizeof(msg), "Can't attach to the process: %s", err_buf); THROW_NEW_DEBUGGER_EXCEPTION(msg); @@ -276,6 +301,10 @@ if (ph != NULL) { Prelease(ph); } + if (saaltroot != NULL) { + free(saaltroot); + saaltroot = NULL; + } } /*