src/os/linux/vm/os_linux.cpp

Print this page
rev 554 : 6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
Summary: Fixed the wrong cast between types since more restrictions are imposed by gcc 4.3.2
Reviewed-by: jcoomes, acorn, phh, never


1143     if (fp) {
1144       statlen = fread(stat, 1, 2047, fp);
1145       stat[statlen] = '\0';
1146       fclose(fp);
1147 
1148       // Skip pid and the command string. Note that we could be dealing with
1149       // weird command names, e.g. user could decide to rename java launcher
1150       // to "java 1.4.2 :)", then the stat file would look like
1151       //                1234 (java 1.4.2 :)) R ... ...
1152       // We don't really need to know the command string, just find the last
1153       // occurrence of ")" and then start parsing from there. See bug 4726580.
1154       char * s = strrchr(stat, ')');
1155 
1156       i = 0;
1157       if (s) {
1158         // Skip blank chars
1159         do s++; while (isspace(*s));
1160 
1161         /*                                     1   1   1   1   1   1   1   1   1   1   2   2   2   2   2   2   2   2   2 */
1162         /*              3  4  5  6  7  8   9   0   1   2   3   4   5   6   7   8   9   0   1   2   3   4   5   6   7   8 */
1163         i = sscanf(s, "%c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld %lu %lu %ld %lu %lu %lu %lu",



1164              &state,          /* 3  %c  */
1165              &ppid,           /* 4  %d  */
1166              &pgrp,           /* 5  %d  */
1167              &session,        /* 6  %d  */
1168              &nr,             /* 7  %d  */
1169              &tpgrp,          /* 8  %d  */
1170              &flags,          /* 9  %lu  */
1171              &minflt,         /* 10 %lu  */
1172              &cminflt,        /* 11 %lu  */
1173              &majflt,         /* 12 %lu  */
1174              &cmajflt,        /* 13 %lu  */
1175              &utime,          /* 14 %lu  */
1176              &stime,          /* 15 %lu  */
1177              &cutime,         /* 16 %ld  */
1178              &cstime,         /* 17 %ld  */
1179              &prio,           /* 18 %ld  */
1180              &nice,           /* 19 %ld  */
1181              &junk,           /* 20 %ld  */
1182              &it_real,        /* 21 %ld  */
1183              &start,          /* 22 %lu  */
1184              &vsize,          /* 23 %lu  */
1185              &rss,            /* 24 %ld  */
1186              &rsslim,         /* 25 %lu  */
1187              &scodes,         /* 26 %lu  */
1188              &ecode,          /* 27 %lu  */
1189              &stack_start);   /* 28 %lu  */
1190       }
1191 
1192       if (i != 28 - 2) {
1193          assert(false, "Bad conversion from /proc/self/stat");
1194          // product mode - assume we are the initial thread, good luck in the
1195          // embedded case.
1196          warning("Can't detect initial thread stack location - bad conversion");
1197          stack_start = (uintptr_t) &rlim;
1198       }
1199     } else {
1200       // For some reason we can't open /proc/self/stat (for example, running on
1201       // FreeBSD with a Linux emulator, or inside chroot), this should work for
1202       // most cases, so don't abort:
1203       warning("Can't detect initial thread stack location - no /proc/self/stat");
1204       stack_start = (uintptr_t) &rlim;
1205     }
1206   }
1207 
1208   // Now we have a pointer (stack_start) very close to the stack top, the
1209   // next thing to do is to figure out the exact location of stack top. We


2041 
2042 // Find the full path to the current module, libjvm.so or libjvm_g.so
2043 void os::jvm_path(char *buf, jint len) {
2044   // Error checking.
2045   if (len < MAXPATHLEN) {
2046     assert(false, "must use a large-enough buffer");
2047     buf[0] = '\0';
2048     return;
2049   }
2050   // Lazy resolve the path to current module.
2051   if (saved_jvm_path[0] != 0) {
2052     strcpy(buf, saved_jvm_path);
2053     return;
2054   }
2055 
2056   char dli_fname[MAXPATHLEN];
2057   bool ret = dll_address_to_library_name(
2058                 CAST_FROM_FN_PTR(address, os::jvm_path),
2059                 dli_fname, sizeof(dli_fname), NULL);
2060   assert(ret != 0, "cannot locate libjvm");
2061   realpath(dli_fname, buf);

2062 
2063   if (strcmp(Arguments::sun_java_launcher(), "gamma") == 0) {
2064     // Support for the gamma launcher.  Typical value for buf is
2065     // "<JAVA_HOME>/jre/lib/<arch>/<vmtype>/libjvm.so".  If "/jre/lib/" appears at
2066     // the right place in the string, then assume we are installed in a JDK and
2067     // we're done.  Otherwise, check for a JAVA_HOME environment variable and fix
2068     // up the path so it looks like libjvm.so is installed there (append a
2069     // fake suffix hotspot/libjvm.so).
2070     const char *p = buf + strlen(buf) - 1;
2071     for (int count = 0; p > buf && count < 5; ++count) {
2072       for (--p; p > buf && *p != '/'; --p)
2073         /* empty */ ;
2074     }
2075 
2076     if (strncmp(p, "/jre/lib/", 9) != 0) {
2077       // Look for JAVA_HOME in the environment.
2078       char* java_home_var = ::getenv("JAVA_HOME");
2079       if (java_home_var != NULL && java_home_var[0] != 0) {
2080         // Check the current module name "libjvm.so" or "libjvm_g.so".
2081         p = strrchr(buf, '/');
2082         assert(strstr(p, "/libjvm") == p, "invalid library name");
2083         p = strstr(p, "_g") ? "_g" : "";
2084 
2085         realpath(java_home_var, buf);

2086         sprintf(buf + strlen(buf), "/jre/lib/%s", cpu_arch);
2087         if (0 == access(buf, F_OK)) {
2088           // Use current module name "libjvm[_g].so" instead of
2089           // "libjvm"debug_only("_g")".so" since for fastdebug version
2090           // we should have "libjvm.so" but debug_only("_g") adds "_g"!
2091           // It is used when we are choosing the HPI library's name
2092           // "libhpi[_g].so" in hpi::initialize_get_interface().
2093           sprintf(buf + strlen(buf), "/hotspot/libjvm%s.so", p);
2094         } else {
2095           // Go back to path of .so
2096           realpath(dli_fname, buf);

2097         }
2098       }
2099     }
2100   }
2101 
2102   strcpy(saved_jvm_path, buf);
2103 }
2104 
2105 void os::print_jni_name_prefix_on(outputStream* st, int args_size) {
2106   // no prefix required, not even "_"
2107 }
2108 
2109 void os::print_jni_name_suffix_on(outputStream* st, int args_size) {
2110   // no suffix required
2111 }
2112 
2113 ////////////////////////////////////////////////////////////////////////////////
2114 // sun.misc.Signal support
2115 
2116 static volatile jint sigint_count = 0;


4201   sprintf(proc_name, proc_stat_path, tid);
4202   fp = fopen(proc_name, "r");
4203   if ( fp == NULL ) return -1;
4204   statlen = fread(stat, 1, 2047, fp);
4205   stat[statlen] = '\0';
4206   fclose(fp);
4207 
4208   // Skip pid and the command string. Note that we could be dealing with
4209   // weird command names, e.g. user could decide to rename java launcher
4210   // to "java 1.4.2 :)", then the stat file would look like
4211   //                1234 (java 1.4.2 :)) R ... ...
4212   // We don't really need to know the command string, just find the last
4213   // occurrence of ")" and then start parsing from there. See bug 4726580.
4214   s = strrchr(stat, ')');
4215   i = 0;
4216   if (s == NULL ) return -1;
4217 
4218   // Skip blank chars
4219   do s++; while (isspace(*s));
4220 
4221   count = sscanf(s,"%c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu",
4222                  &idummy, &idummy, &idummy, &idummy, &idummy, &idummy,
4223                  &ldummy, &ldummy, &ldummy, &ldummy, &ldummy,
4224                  &user_time, &sys_time);
4225   if ( count != 13 ) return -1;
4226   if (user_sys_cpu_time) {
4227     return ((jlong)sys_time + (jlong)user_time) * (1000000000 / clock_tics_per_sec);
4228   } else {
4229     return (jlong)user_time * (1000000000 / clock_tics_per_sec);
4230   }
4231 }
4232 
4233 void os::current_thread_cpu_time_info(jvmtiTimerInfo *info_ptr) {
4234   info_ptr->max_value = ALL_64_BITS;       // will not wrap in less than 64 bits
4235   info_ptr->may_skip_backward = false;     // elapsed time not wall time
4236   info_ptr->may_skip_forward = false;      // elapsed time not wall time
4237   info_ptr->kind = JVMTI_TIMER_TOTAL_CPU;  // user+system time is returned
4238 }
4239 
4240 void os::thread_cpu_time_info(jvmtiTimerInfo *info_ptr) {
4241   info_ptr->max_value = ALL_64_BITS;       // will not wrap in less than 64 bits
4242   info_ptr->may_skip_backward = false;     // elapsed time not wall time
4243   info_ptr->may_skip_forward = false;      // elapsed time not wall time
4244   info_ptr->kind = JVMTI_TIMER_TOTAL_CPU;  // user+system time is returned
4245 }




1143     if (fp) {
1144       statlen = fread(stat, 1, 2047, fp);
1145       stat[statlen] = '\0';
1146       fclose(fp);
1147 
1148       // Skip pid and the command string. Note that we could be dealing with
1149       // weird command names, e.g. user could decide to rename java launcher
1150       // to "java 1.4.2 :)", then the stat file would look like
1151       //                1234 (java 1.4.2 :)) R ... ...
1152       // We don't really need to know the command string, just find the last
1153       // occurrence of ")" and then start parsing from there. See bug 4726580.
1154       char * s = strrchr(stat, ')');
1155 
1156       i = 0;
1157       if (s) {
1158         // Skip blank chars
1159         do s++; while (isspace(*s));
1160 
1161         /*                                     1   1   1   1   1   1   1   1   1   1   2   2   2   2   2   2   2   2   2 */
1162         /*              3  4  5  6  7  8   9   0   1   2   3   4   5   6   7   8   9   0   1   2   3   4   5   6   7   8 */
1163         i = sscanf(s, "%c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld "
1164                    UINTX_FORMAT UINTX_FORMAT UINTX_FORMAT
1165                    " %lu "
1166                    UINTX_FORMAT UINTX_FORMAT UINTX_FORMAT,
1167              &state,          /* 3  %c  */
1168              &ppid,           /* 4  %d  */
1169              &pgrp,           /* 5  %d  */
1170              &session,        /* 6  %d  */
1171              &nr,             /* 7  %d  */
1172              &tpgrp,          /* 8  %d  */
1173              &flags,          /* 9  %lu  */
1174              &minflt,         /* 10 %lu  */
1175              &cminflt,        /* 11 %lu  */
1176              &majflt,         /* 12 %lu  */
1177              &cmajflt,        /* 13 %lu  */
1178              &utime,          /* 14 %lu  */
1179              &stime,          /* 15 %lu  */
1180              &cutime,         /* 16 %ld  */
1181              &cstime,         /* 17 %ld  */
1182              &prio,           /* 18 %ld  */
1183              &nice,           /* 19 %ld  */
1184              &junk,           /* 20 %ld  */
1185              &it_real,        /* 21 %ld  */
1186              &start,          /* 22 UINTX_FORMAT  */
1187              &vsize,          /* 23 UINTX_FORMAT  */
1188              &rss,            /* 24 UINTX_FORMAT  */
1189              &rsslim,         /* 25 %lu  */
1190              &scodes,         /* 26 UINTX_FORMAT  */
1191              &ecode,          /* 27 UINTX_FORMAT  */
1192              &stack_start);   /* 28 UINTX_FORMAT  */
1193       }
1194 
1195       if (i != 28 - 2) {
1196          assert(false, "Bad conversion from /proc/self/stat");
1197          // product mode - assume we are the initial thread, good luck in the
1198          // embedded case.
1199          warning("Can't detect initial thread stack location - bad conversion");
1200          stack_start = (uintptr_t) &rlim;
1201       }
1202     } else {
1203       // For some reason we can't open /proc/self/stat (for example, running on
1204       // FreeBSD with a Linux emulator, or inside chroot), this should work for
1205       // most cases, so don't abort:
1206       warning("Can't detect initial thread stack location - no /proc/self/stat");
1207       stack_start = (uintptr_t) &rlim;
1208     }
1209   }
1210 
1211   // Now we have a pointer (stack_start) very close to the stack top, the
1212   // next thing to do is to figure out the exact location of stack top. We


2044 
2045 // Find the full path to the current module, libjvm.so or libjvm_g.so
2046 void os::jvm_path(char *buf, jint len) {
2047   // Error checking.
2048   if (len < MAXPATHLEN) {
2049     assert(false, "must use a large-enough buffer");
2050     buf[0] = '\0';
2051     return;
2052   }
2053   // Lazy resolve the path to current module.
2054   if (saved_jvm_path[0] != 0) {
2055     strcpy(buf, saved_jvm_path);
2056     return;
2057   }
2058 
2059   char dli_fname[MAXPATHLEN];
2060   bool ret = dll_address_to_library_name(
2061                 CAST_FROM_FN_PTR(address, os::jvm_path),
2062                 dli_fname, sizeof(dli_fname), NULL);
2063   assert(ret != 0, "cannot locate libjvm");
2064   if (realpath(dli_fname, buf) == NULL)
2065     return;
2066 
2067   if (strcmp(Arguments::sun_java_launcher(), "gamma") == 0) {
2068     // Support for the gamma launcher.  Typical value for buf is
2069     // "<JAVA_HOME>/jre/lib/<arch>/<vmtype>/libjvm.so".  If "/jre/lib/" appears at
2070     // the right place in the string, then assume we are installed in a JDK and
2071     // we're done.  Otherwise, check for a JAVA_HOME environment variable and fix
2072     // up the path so it looks like libjvm.so is installed there (append a
2073     // fake suffix hotspot/libjvm.so).
2074     const char *p = buf + strlen(buf) - 1;
2075     for (int count = 0; p > buf && count < 5; ++count) {
2076       for (--p; p > buf && *p != '/'; --p)
2077         /* empty */ ;
2078     }
2079 
2080     if (strncmp(p, "/jre/lib/", 9) != 0) {
2081       // Look for JAVA_HOME in the environment.
2082       char* java_home_var = ::getenv("JAVA_HOME");
2083       if (java_home_var != NULL && java_home_var[0] != 0) {
2084         // Check the current module name "libjvm.so" or "libjvm_g.so".
2085         p = strrchr(buf, '/');
2086         assert(strstr(p, "/libjvm") == p, "invalid library name");
2087         p = strstr(p, "_g") ? "_g" : "";
2088 
2089         if (realpath(java_home_var, buf) == NULL)
2090           return;
2091         sprintf(buf + strlen(buf), "/jre/lib/%s", cpu_arch);
2092         if (0 == access(buf, F_OK)) {
2093           // Use current module name "libjvm[_g].so" instead of
2094           // "libjvm"debug_only("_g")".so" since for fastdebug version
2095           // we should have "libjvm.so" but debug_only("_g") adds "_g"!
2096           // It is used when we are choosing the HPI library's name
2097           // "libhpi[_g].so" in hpi::initialize_get_interface().
2098           sprintf(buf + strlen(buf), "/hotspot/libjvm%s.so", p);
2099         } else {
2100           // Go back to path of .so
2101           if (realpath(dli_fname, buf) == NULL)
2102             return;
2103         }
2104       }
2105     }
2106   }
2107 
2108   strcpy(saved_jvm_path, buf);
2109 }
2110 
2111 void os::print_jni_name_prefix_on(outputStream* st, int args_size) {
2112   // no prefix required, not even "_"
2113 }
2114 
2115 void os::print_jni_name_suffix_on(outputStream* st, int args_size) {
2116   // no suffix required
2117 }
2118 
2119 ////////////////////////////////////////////////////////////////////////////////
2120 // sun.misc.Signal support
2121 
2122 static volatile jint sigint_count = 0;


4207   sprintf(proc_name, proc_stat_path, tid);
4208   fp = fopen(proc_name, "r");
4209   if ( fp == NULL ) return -1;
4210   statlen = fread(stat, 1, 2047, fp);
4211   stat[statlen] = '\0';
4212   fclose(fp);
4213 
4214   // Skip pid and the command string. Note that we could be dealing with
4215   // weird command names, e.g. user could decide to rename java launcher
4216   // to "java 1.4.2 :)", then the stat file would look like
4217   //                1234 (java 1.4.2 :)) R ... ...
4218   // We don't really need to know the command string, just find the last
4219   // occurrence of ")" and then start parsing from there. See bug 4726580.
4220   s = strrchr(stat, ')');
4221   i = 0;
4222   if (s == NULL ) return -1;
4223 
4224   // Skip blank chars
4225   do s++; while (isspace(*s));
4226 
4227   count = sscanf(s,"%*c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu",
4228                  &idummy, &idummy, &idummy, &idummy, &idummy,
4229                  &ldummy, &ldummy, &ldummy, &ldummy, &ldummy,
4230                  &user_time, &sys_time);
4231   if ( count != 12 ) return -1;
4232   if (user_sys_cpu_time) {
4233     return ((jlong)sys_time + (jlong)user_time) * (1000000000 / clock_tics_per_sec);
4234   } else {
4235     return (jlong)user_time * (1000000000 / clock_tics_per_sec);
4236   }
4237 }
4238 
4239 void os::current_thread_cpu_time_info(jvmtiTimerInfo *info_ptr) {
4240   info_ptr->max_value = ALL_64_BITS;       // will not wrap in less than 64 bits
4241   info_ptr->may_skip_backward = false;     // elapsed time not wall time
4242   info_ptr->may_skip_forward = false;      // elapsed time not wall time
4243   info_ptr->kind = JVMTI_TIMER_TOTAL_CPU;  // user+system time is returned
4244 }
4245 
4246 void os::thread_cpu_time_info(jvmtiTimerInfo *info_ptr) {
4247   info_ptr->max_value = ALL_64_BITS;       // will not wrap in less than 64 bits
4248   info_ptr->may_skip_backward = false;     // elapsed time not wall time
4249   info_ptr->may_skip_forward = false;      // elapsed time not wall time
4250   info_ptr->kind = JVMTI_TIMER_TOTAL_CPU;  // user+system time is returned
4251 }