1 /*
2 * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * - Neither the name of Oracle nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
877 char number[MAX_TOKEN_LENGTH];
878
879 next = get_token(next, ",=", number, (int)sizeof(number));
880 if ( next == NULL ) {
881 fatal_error("ERROR: Cannot parse maxDump=number: %s\n", options);
882 }
883 gdata->maxDump = atoi(number);
884 } else if ( token[0]!=0 ) {
885 /* We got a non-empty token and we don't know what it is. */
886 fatal_error("ERROR: Unknown option: %s\n", token);
887 }
888 /* Get the next token (returns NULL if there are no more) */
889 next = get_token(next, ",=", token, (int)sizeof(token));
890 }
891 }
892
893 /* Agent_OnLoad: This is called immediately after the shared library is
894 * loaded. This is the first code executed.
895 */
896 JNIEXPORT jint JNICALL
897 Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
898 {
899 static GlobalAgentData data;
900 jvmtiEnv *jvmti;
901 jvmtiError error;
902 jint res;
903 TraceFlavor flavor;
904 jvmtiCapabilities capabilities;
905 jvmtiEventCallbacks callbacks;
906 static Trace empty;
907
908 /* Setup initial global agent data area
909 * Use of static/extern data should be handled carefully here.
910 * We need to make sure that we are able to cleanup after ourselves
911 * so anything allocated in this library needs to be freed in
912 * the Agent_OnUnload() function.
913 */
914 (void)memset((void*)&data, 0, sizeof(data));
915 gdata = &data;
916
917 /* First thing we need to do is get the jvmtiEnv* or JVMTI environment */
993 error = (*jvmti)->CreateRawMonitor(jvmti, "agent data", &(gdata->lock));
994 check_jvmti_error(jvmti, error, "Cannot create raw monitor");
995
996 /* Create the TraceInfo for various flavors of empty traces */
997 for ( flavor = TRACE_FIRST ; flavor <= TRACE_LAST ; flavor++ ) {
998 gdata->emptyTrace[flavor] =
999 newTraceInfo(&empty, hashTrace(&empty), flavor);
1000 }
1001
1002 /* Add jar file to boot classpath */
1003 add_demo_jar_to_bootclasspath(jvmti, "heapTracker");
1004
1005 /* We return JNI_OK to signify success */
1006 return JNI_OK;
1007 }
1008
1009 /* Agent_OnUnload: This is called immediately before the shared library is
1010 * unloaded. This is the last code executed.
1011 */
1012 JNIEXPORT void JNICALL
1013 Agent_OnUnload(JavaVM *vm)
1014 {
1015 /* Skip any cleanup, VM is about to die anyway */
1016 }
|
1 /*
2 * Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * - Neither the name of Oracle nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
877 char number[MAX_TOKEN_LENGTH];
878
879 next = get_token(next, ",=", number, (int)sizeof(number));
880 if ( next == NULL ) {
881 fatal_error("ERROR: Cannot parse maxDump=number: %s\n", options);
882 }
883 gdata->maxDump = atoi(number);
884 } else if ( token[0]!=0 ) {
885 /* We got a non-empty token and we don't know what it is. */
886 fatal_error("ERROR: Unknown option: %s\n", token);
887 }
888 /* Get the next token (returns NULL if there are no more) */
889 next = get_token(next, ",=", token, (int)sizeof(token));
890 }
891 }
892
893 /* Agent_OnLoad: This is called immediately after the shared library is
894 * loaded. This is the first code executed.
895 */
896 JNIEXPORT jint JNICALL
897 DEF_Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
898 {
899 static GlobalAgentData data;
900 jvmtiEnv *jvmti;
901 jvmtiError error;
902 jint res;
903 TraceFlavor flavor;
904 jvmtiCapabilities capabilities;
905 jvmtiEventCallbacks callbacks;
906 static Trace empty;
907
908 /* Setup initial global agent data area
909 * Use of static/extern data should be handled carefully here.
910 * We need to make sure that we are able to cleanup after ourselves
911 * so anything allocated in this library needs to be freed in
912 * the Agent_OnUnload() function.
913 */
914 (void)memset((void*)&data, 0, sizeof(data));
915 gdata = &data;
916
917 /* First thing we need to do is get the jvmtiEnv* or JVMTI environment */
993 error = (*jvmti)->CreateRawMonitor(jvmti, "agent data", &(gdata->lock));
994 check_jvmti_error(jvmti, error, "Cannot create raw monitor");
995
996 /* Create the TraceInfo for various flavors of empty traces */
997 for ( flavor = TRACE_FIRST ; flavor <= TRACE_LAST ; flavor++ ) {
998 gdata->emptyTrace[flavor] =
999 newTraceInfo(&empty, hashTrace(&empty), flavor);
1000 }
1001
1002 /* Add jar file to boot classpath */
1003 add_demo_jar_to_bootclasspath(jvmti, "heapTracker");
1004
1005 /* We return JNI_OK to signify success */
1006 return JNI_OK;
1007 }
1008
1009 /* Agent_OnUnload: This is called immediately before the shared library is
1010 * unloaded. This is the last code executed.
1011 */
1012 JNIEXPORT void JNICALL
1013 DEF_Agent_OnUnload(JavaVM *vm)
1014 {
1015 /* Skip any cleanup, VM is about to die anyway */
1016 }
|