From c6c05ae8ef65608a908b3033c640ea631aeedc6e Mon Sep 17 00:00:00 2001 From: xlu Date: Wed, 24 Dec 2008 19:13:53 -0800 Subject: [PATCH] 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 --- src/cpu/sparc/vm/jni_sparc.h | 8 ++++- src/cpu/x86/vm/jni_x86.h | 6 ++++ src/os/linux/vm/os_linux.cpp | 32 ++++++++++++-------- src/share/vm/classfile/javaClasses.cpp | 2 +- src/share/vm/libadt/port.hpp | 11 ------- src/share/vm/oops/constantPoolOop.cpp | 2 +- src/share/vm/oops/oopsHierarchy.hpp | 3 ++ src/share/vm/opto/idealGraphPrinter.cpp | 2 +- src/share/vm/prims/jvm.cpp | 3 +- src/share/vm/runtime/arguments.cpp | 2 +- src/share/vm/runtime/memprofiler.cpp | 31 ++++++++++--------- src/share/vm/runtime/safepoint.cpp | 2 +- src/share/vm/runtime/synchronizer.cpp | 2 +- src/share/vm/utilities/globalDefinitions.hpp | 11 ++++++- src/share/vm/utilities/ostream.cpp | 10 ++++-- src/share/vm/utilities/vmError.hpp | 2 +- 16 files changed, 78 insertions(+), 51 deletions(-) diff --git a/src/cpu/sparc/vm/jni_sparc.h b/src/cpu/sparc/vm/jni_sparc.h index 7d2845e01..33a494b60 100644 --- a/src/cpu/sparc/vm/jni_sparc.h +++ b/src/cpu/sparc/vm/jni_sparc.h @@ -28,5 +28,11 @@ #define JNICALL typedef int jint; -typedef long long jlong; + +#ifdef _LP64 + typedef long jlong; +#else + typedef long long jlong; +#endif + typedef signed char jbyte; diff --git a/src/cpu/x86/vm/jni_x86.h b/src/cpu/x86/vm/jni_x86.h index 89f95e357..625562bb3 100644 --- a/src/cpu/x86/vm/jni_x86.h +++ b/src/cpu/x86/vm/jni_x86.h @@ -32,7 +32,13 @@ #define JNICALL typedef int jint; + +#ifdef _LP64 + typedef long jlong; +#else typedef long long jlong; +#endif + #else #define JNIEXPORT __declspec(dllexport) #define JNIIMPORT __declspec(dllimport) diff --git a/src/os/linux/vm/os_linux.cpp b/src/os/linux/vm/os_linux.cpp index 3b8c0b4dc..4bb6d26f4 100644 --- a/src/os/linux/vm/os_linux.cpp +++ b/src/os/linux/vm/os_linux.cpp @@ -1160,7 +1160,10 @@ void os::Linux::capture_initial_stack(size_t max_size) { /* 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 */ /* 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 */ - 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", + i = sscanf(s, "%c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld " + UINTX_FORMAT UINTX_FORMAT UINTX_FORMAT + " %lu " + UINTX_FORMAT UINTX_FORMAT UINTX_FORMAT, &state, /* 3 %c */ &ppid, /* 4 %d */ &pgrp, /* 5 %d */ @@ -1180,13 +1183,13 @@ void os::Linux::capture_initial_stack(size_t max_size) { &nice, /* 19 %ld */ &junk, /* 20 %ld */ &it_real, /* 21 %ld */ - &start, /* 22 %lu */ - &vsize, /* 23 %lu */ - &rss, /* 24 %ld */ + &start, /* 22 UINTX_FORMAT */ + &vsize, /* 23 UINTX_FORMAT */ + &rss, /* 24 UINTX_FORMAT */ &rsslim, /* 25 %lu */ - &scodes, /* 26 %lu */ - &ecode, /* 27 %lu */ - &stack_start); /* 28 %lu */ + &scodes, /* 26 UINTX_FORMAT */ + &ecode, /* 27 UINTX_FORMAT */ + &stack_start); /* 28 UINTX_FORMAT */ } if (i != 28 - 2) { @@ -2024,7 +2027,8 @@ void os::jvm_path(char *buf, jint len) { CAST_FROM_FN_PTR(address, os::jvm_path), dli_fname, sizeof(dli_fname), NULL); assert(ret != 0, "cannot locate libjvm"); - realpath(dli_fname, buf); + if (realpath(dli_fname, buf) == NULL) + return; if (strcmp(Arguments::sun_java_launcher(), "gamma") == 0) { // Support for the gamma launcher. Typical value for buf is @@ -2048,7 +2052,8 @@ void os::jvm_path(char *buf, jint len) { assert(strstr(p, "/libjvm") == p, "invalid library name"); p = strstr(p, "_g") ? "_g" : ""; - realpath(java_home_var, buf); + if (realpath(java_home_var, buf) == NULL) + return; sprintf(buf + strlen(buf), "/jre/lib/%s", cpu_arch); if (0 == access(buf, F_OK)) { // Use current module name "libjvm[_g].so" instead of @@ -2059,7 +2064,8 @@ void os::jvm_path(char *buf, jint len) { sprintf(buf + strlen(buf), "/hotspot/libjvm%s.so", p); } else { // Go back to path of .so - realpath(dli_fname, buf); + if (realpath(dli_fname, buf) == NULL) + return; } } } @@ -4184,11 +4190,11 @@ static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time) { // Skip blank chars do s++; while (isspace(*s)); - count = sscanf(s,"%c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu", - &idummy, &idummy, &idummy, &idummy, &idummy, &idummy, + count = sscanf(s,"%*c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu", + &idummy, &idummy, &idummy, &idummy, &idummy, &ldummy, &ldummy, &ldummy, &ldummy, &ldummy, &user_time, &sys_time); - if ( count != 13 ) return -1; + if ( count != 12 ) return -1; if (user_sys_cpu_time) { return ((jlong)sys_time + (jlong)user_time) * (1000000000 / clock_tics_per_sec); } else { diff --git a/src/share/vm/classfile/javaClasses.cpp b/src/share/vm/classfile/javaClasses.cpp index ea68a3667..15677b964 100644 --- a/src/share/vm/classfile/javaClasses.cpp +++ b/src/share/vm/classfile/javaClasses.cpp @@ -866,7 +866,7 @@ char* java_lang_Throwable::print_stack_element_to_buffer(methodOop method, int b } nmethod* nm = method->code(); if (WizardMode && nm != NULL) { - sprintf(buf + (int)strlen(buf), "(nmethod %#x)", nm); + sprintf(buf + (int)strlen(buf), "(nmethod " PTR_FORMAT ")", (intptr_t)nm); } } diff --git a/src/share/vm/libadt/port.hpp b/src/share/vm/libadt/port.hpp index 70034d09b..68a84f1a4 100644 --- a/src/share/vm/libadt/port.hpp +++ b/src/share/vm/libadt/port.hpp @@ -34,17 +34,6 @@ #include #include #include -#undef bzero -inline void bzero(void *b, int len) { memset(b,0,len); } -#undef bcopy -inline void bcopy(const void *s, void *d, size_t len) { memmove(d,s,len); } -#undef bcmp -inline int bcmp(const void *s,const void *t,int len) { return memcmp(s,t,len);} -extern "C" unsigned long strtoul(const char *s, char **end, int base); - -// Definition for sys_errlist varies from Sun 4.1 & Solaris. -// We use the new Solaris definition. -#include // Access to the C++ class virtual function pointer // Put the class in the macro diff --git a/src/share/vm/oops/constantPoolOop.cpp b/src/share/vm/oops/constantPoolOop.cpp index 263b7bbe4..bc12c8f2c 100644 --- a/src/share/vm/oops/constantPoolOop.cpp +++ b/src/share/vm/oops/constantPoolOop.cpp @@ -962,7 +962,7 @@ static void print_cpool_bytes(jint cnt, u1 *bytes) { } case JVM_CONSTANT_Long: { u8 val = Bytes::get_Java_u8(bytes); - printf("long %lldl", *(jlong *) &val); + printf("long "INT64_FORMAT, *(jlong *) &val); ent_size = 8; idx++; // Long takes two cpool slots break; diff --git a/src/share/vm/oops/oopsHierarchy.hpp b/src/share/vm/oops/oopsHierarchy.hpp index 597dafe3d..06c64d0e4 100644 --- a/src/share/vm/oops/oopsHierarchy.hpp +++ b/src/share/vm/oops/oopsHierarchy.hpp @@ -126,8 +126,11 @@ public: operator jobject () const { return (jobject)obj(); } // from javaClasses.cpp operator JavaThread* () const { return (JavaThread*)obj(); } + +#ifndef _LP64 // from jvm.cpp operator jlong* () const { return (jlong*)obj(); } +#endif // from parNewGeneration and other things that want to get to the end of // an oop for stuff (like constMethodKlass.cpp, objArrayKlass.cpp) diff --git a/src/share/vm/opto/idealGraphPrinter.cpp b/src/share/vm/opto/idealGraphPrinter.cpp index 6dfc5fc9c..ad45b566e 100644 --- a/src/share/vm/opto/idealGraphPrinter.cpp +++ b/src/share/vm/opto/idealGraphPrinter.cpp @@ -557,7 +557,7 @@ void IdealGraphPrinter::visit_node(Node *n, void *param) { // max. 2 chars allowed if (value >= -9 && value <= 99) { - sprintf(buffer, "%d", value); + sprintf(buffer, INT64_FORMAT, value); print_prop(short_name, buffer); } else { print_prop(short_name, "L"); diff --git a/src/share/vm/prims/jvm.cpp b/src/share/vm/prims/jvm.cpp index 7f832341c..1835594ba 100644 --- a/src/share/vm/prims/jvm.cpp +++ b/src/share/vm/prims/jvm.cpp @@ -2475,7 +2475,8 @@ void jio_print(const char* s) { if (Arguments::vfprintf_hook() != NULL) { jio_fprintf(defaultStream::output_stream(), "%s", s); } else { - ::write(defaultStream::output_fd(), s, (int)strlen(s)); + // Make an unused local variable to avoid warning from gcc 4.x compiler. + size_t count = ::write(defaultStream::output_fd(), s, (int)strlen(s)); } } diff --git a/src/share/vm/runtime/arguments.cpp b/src/share/vm/runtime/arguments.cpp index b9c943d10..ce9725bed 100644 --- a/src/share/vm/runtime/arguments.cpp +++ b/src/share/vm/runtime/arguments.cpp @@ -1361,7 +1361,7 @@ void Arguments::set_aggressive_opts_flags() { // Feed the cache size setting into the JDK char buffer[1024]; - sprintf(buffer, "java.lang.Integer.IntegerCache.high=%d", AutoBoxCacheMax); + sprintf(buffer, "java.lang.Integer.IntegerCache.high=" INTX_FORMAT, AutoBoxCacheMax); add_property(buffer); } if (AggressiveOpts && FLAG_IS_DEFAULT(DoEscapeAnalysis)) { diff --git a/src/share/vm/runtime/memprofiler.cpp b/src/share/vm/runtime/memprofiler.cpp index 4d5ad533d..f8a259f9b 100644 --- a/src/share/vm/runtime/memprofiler.cpp +++ b/src/share/vm/runtime/memprofiler.cpp @@ -104,21 +104,22 @@ void MemProfiler::do_trace() { } // Print trace line in log - fprintf(_log_fp, "%6.1f,%5d,%5d,%6ld,%6ld,%6ld,%6ld,", - os::elapsedTime(), - Threads::number_of_threads(), - SystemDictionary::number_of_classes(), - Universe::heap()->used() / K, - Universe::heap()->capacity() / K, - Universe::heap()->permanent_used() / HWperKB, - Universe::heap()->permanent_capacity() / HWperKB); - - fprintf(_log_fp, "%6ld,", CodeCache::capacity() / K); - - fprintf(_log_fp, "%6ld,%6ld,%6ld\n", - handles_memory_usage / K, - resource_memory_usage / K, - OopMapCache::memory_usage() / K); + fprintf(_log_fp, "%6.1f,%5d,%5d," UINTX_FORMAT_W(6) "," UINTX_FORMAT_W(6) "," + UINTX_FORMAT_W(6) "," UINTX_FORMAT_W(6) ",", + os::elapsedTime(), + Threads::number_of_threads(), + SystemDictionary::number_of_classes(), + Universe::heap()->used() / K, + Universe::heap()->capacity() / K, + Universe::heap()->permanent_used() / HWperKB, + Universe::heap()->permanent_capacity() / HWperKB); + + fprintf(_log_fp, UINTX_FORMAT_W(6) ",", CodeCache::capacity() / K); + + fprintf(_log_fp, UINTX_FORMAT_W(6) "," UINTX_FORMAT_W(6) ",%6ld\n", + handles_memory_usage / K, + resource_memory_usage / K, + OopMapCache::memory_usage() / K); fflush(_log_fp); } diff --git a/src/share/vm/runtime/safepoint.cpp b/src/share/vm/runtime/safepoint.cpp index 2a3b838f6..c13af643a 100644 --- a/src/share/vm/runtime/safepoint.cpp +++ b/src/share/vm/runtime/safepoint.cpp @@ -730,7 +730,7 @@ void SafepointSynchronize::print_safepoint_timeout(SafepointTimeoutReason reason if (DieOnSafepointTimeout) { char msg[1024]; VM_Operation *op = VMThread::vm_operation(); - sprintf(msg, "Safepoint sync time longer than %d ms detected when executing %s.", + sprintf(msg, "Safepoint sync time longer than " INTX_FORMAT "ms detected when executing %s.", SafepointTimeoutDelay, op != NULL ? op->name() : "no vm operation"); fatal(msg); diff --git a/src/share/vm/runtime/synchronizer.cpp b/src/share/vm/runtime/synchronizer.cpp index aeb66980a..e0f3cfe04 100644 --- a/src/share/vm/runtime/synchronizer.cpp +++ b/src/share/vm/runtime/synchronizer.cpp @@ -424,7 +424,7 @@ void ObjectSynchronizer::Initialize () { // asserts is that error message -- often something about negative array // indices -- is opaque. -#define CTASSERT(x) { int tag[1-(2*!(x))]; printf ("Tag @%X\n", tag); } +#define CTASSERT(x) { int tag[1-(2*!(x))]; printf ("Tag @" INTPTR_FORMAT "\n", (intptr_t)tag); } void ObjectMonitor::ctAsserts() { CTASSERT(offset_of (ObjectMonitor, _header) == 0); diff --git a/src/share/vm/utilities/globalDefinitions.hpp b/src/share/vm/utilities/globalDefinitions.hpp index f87bfad69..93b2a2b67 100644 --- a/src/share/vm/utilities/globalDefinitions.hpp +++ b/src/share/vm/utilities/globalDefinitions.hpp @@ -1087,15 +1087,24 @@ inline int build_int_from_shorts( jushort low, jushort high ) { // Format macros that allow the field width to be specified. The width must be // a string literal (e.g., "8") or a macro that evaluates to one. #ifdef _LP64 +#define UINTX_FORMAT_W(width) UINT64_FORMAT_W(width) #define SSIZE_FORMAT_W(width) INT64_FORMAT_W(width) #define SIZE_FORMAT_W(width) UINT64_FORMAT_W(width) #else +#define UINTX_FORMAT_W(width) UINT32_FORMAT_W(width) #define SSIZE_FORMAT_W(width) INT32_FORMAT_W(width) #define SIZE_FORMAT_W(width) UINT32_FORMAT_W(width) #endif // _LP64 // Format pointers and size_t (or size_t-like integer types) which change size -// between 32- and 64-bit. +// between 32- and 64-bit. The pointer format theoretically should be "%p", +// however, it has different output on different platforms. On Windows, the data +// will be padded with zeros automatically. On Solaris, we can use "%016p" & +// "%08p" on 64 bit & 32 bit platforms to make the data padded with extra zeros. +// On Linux, "%016p" or "%08p" is not be allowed, at least on the latest GCC +// 4.3.2. So we have to use "%016x" or "%08x" to simulate the printing format. +// GCC 4.3.2, however requires the data to be converted to "intptr_t" when +// using "%x". #ifdef _LP64 #define PTR_FORMAT PTR64_FORMAT #define UINTX_FORMAT UINT64_FORMAT diff --git a/src/share/vm/utilities/ostream.cpp b/src/share/vm/utilities/ostream.cpp index 8770bed52..65d18802b 100644 --- a/src/share/vm/utilities/ostream.cpp +++ b/src/share/vm/utilities/ostream.cpp @@ -300,7 +300,10 @@ fileStream::fileStream(const char* file_name) { } void fileStream::write(const char* s, size_t len) { - if (_file != NULL) fwrite(s, 1, len, _file); + if (_file != NULL) { + // Make an unused local variable to avoid warning from gcc 4.x compiler. + size_t count = fwrite(s, 1, len, _file); + } update_position(s, len); } @@ -328,7 +331,10 @@ fdStream::~fdStream() { } void fdStream::write(const char* s, size_t len) { - if (_fd != -1) ::write(_fd, s, (int)len); + if (_fd != -1) { + // Make an unused local variable to avoid warning from gcc 4.x compiler. + size_t count = ::write(_fd, s, (int)len); + } update_position(s, len); } diff --git a/src/share/vm/utilities/vmError.hpp b/src/share/vm/utilities/vmError.hpp index 414bc7f21..8e618d914 100644 --- a/src/share/vm/utilities/vmError.hpp +++ b/src/share/vm/utilities/vmError.hpp @@ -50,7 +50,7 @@ class VMError : public StackObj { // additional info for VM internal errors const char * _filename; - int _lineno; + size_t _lineno; // used by fatal error handler int _current_step; -- GitLab