1792 st->print_cr("Error: Cannot print dynamic libraries.");
1793 return;
1794 }
1795 dlinfo(handle, RTLD_DI_LINKMAP, &map);
1796 if (map == NULL) {
1797 st->print_cr("Error: Cannot print dynamic libraries.");
1798 return;
1799 }
1800
1801 while (map->l_prev != NULL)
1802 map = map->l_prev;
1803
1804 while (map != NULL) {
1805 st->print_cr(PTR_FORMAT " \t%s", map->l_addr, map->l_name);
1806 map = map->l_next;
1807 }
1808
1809 dlclose(handle);
1810 }
1811
1812 // Loads .dll/.so and
1813 // in case of error it checks if .dll/.so was built for the
1814 // same architecture as Hotspot is running on
1815
1816 void * os::dll_load(const char *filename, char *ebuf, int ebuflen)
1817 {
1818 void * result= ::dlopen(filename, RTLD_LAZY);
1819 if (result != NULL) {
1820 // Successful loading
1821 return result;
1822 }
1823
1824 Elf32_Ehdr elf_head;
1825
1826 // Read system error message into ebuf
1827 // It may or may not be overwritten below
1828 ::strncpy(ebuf, ::dlerror(), ebuflen-1);
1829 ebuf[ebuflen-1]='\0';
1830 int diag_msg_max_length=ebuflen-strlen(ebuf);
1831 char* diag_msg_buf=ebuf+strlen(ebuf);
3234 assert(newtime >= prevtime, "time moving backwards");
3235 /* Doing prevtime and newtime in microseconds doesn't help precision,
3236 and trying to round up to avoid lost milliseconds can result in a
3237 too-short delay. */
3238 millis -= newtime - prevtime;
3239 if(millis <= 0)
3240 return OS_OK;
3241 prevtime = newtime;
3242 } else
3243 return res;
3244 }
3245
3246 return OS_OK;
3247 }
3248
3249 // Read calls from inside the vm need to perform state transitions
3250 size_t os::read(int fd, void *buf, unsigned int nBytes) {
3251 INTERRUPTIBLE_RETURN_INT_VM(::read(fd, buf, nBytes), os::Solaris::clear_interrupted);
3252 }
3253
3254 size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
3255 INTERRUPTIBLE_RETURN_INT(::read(fd, buf, nBytes), os::Solaris::clear_interrupted);
3256 }
3257
3258 int os::sleep(Thread* thread, jlong millis, bool interruptible) {
3259 assert(thread == Thread::current(), "thread consistency check");
3260
3261 // TODO-FIXME: this should be removed.
3262 // On Solaris machines (especially 2.5.1) we found that sometimes the VM gets into a live lock
3263 // situation with a JavaThread being starved out of a lwp. The kernel doesn't seem to generate
3264 // a SIGWAITING signal which would enable the threads library to create a new lwp for the starving
3265 // thread. We suspect that because the Watcher thread keeps waking up at periodic intervals the kernel
3266 // is fooled into believing that the system is making progress. In the code below we block the
3267 // the watcher thread while safepoint is in progress so that it would not appear as though the
3268 // system is making progress.
3269 if (!Solaris::T2_libthread() &&
3270 thread->is_Watcher_thread() && SafepointSynchronize::is_synchronizing() && !Arguments::has_profile()) {
3271 // We now try to acquire the threads lock. Since this lock is held by the VM thread during
3272 // the entire safepoint, the watcher thread will line up here during the safepoint.
3273 Threads_lock->lock_without_safepoint_check();
5131 where = RTLD_DEFAULT;
5132 if ((sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "__vsnprintf"))) == NULL)
5133 sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "vsnprintf"));
5134 assert(sol_vsnprintf != NULL, "vsnprintf not found");
5135 }
5136 }
5137 return (*sol_vsnprintf)(buf, count, fmt, argptr);
5138 }
5139
5140
5141 // Is a (classpath) directory empty?
5142 bool os::dir_is_empty(const char* path) {
5143 DIR *dir = NULL;
5144 struct dirent *ptr;
5145
5146 dir = opendir(path);
5147 if (dir == NULL) return true;
5148
5149 /* Scan the directory */
5150 bool result = true;
5151 char buf[sizeof(struct dirent) + MAX_PATH];
5152 struct dirent *dbuf = (struct dirent *) buf;
5153 while (result && (ptr = readdir(dir, dbuf)) != NULL) {
5154 if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
5155 result = false;
5156 }
5157 }
5158 closedir(dir);
5159 return result;
5160 }
5161
5162 // This code originates from JDK's sysOpen and open64_w
5163 // from src/solaris/hpi/src/system_md.c
5164
5165 #ifndef O_DELETE
5166 #define O_DELETE 0x10000
5167 #endif
5168
5169 // Open a file. Unlink the file immediately after open returns
5170 // if the specified oflag has the O_DELETE flag set.
5171 // O_DELETE is used only in j2se/src/share/native/java/util/zip/ZipFile.c
5172
5173 int os::open(const char *path, int oflag, int mode) {
|
1792 st->print_cr("Error: Cannot print dynamic libraries.");
1793 return;
1794 }
1795 dlinfo(handle, RTLD_DI_LINKMAP, &map);
1796 if (map == NULL) {
1797 st->print_cr("Error: Cannot print dynamic libraries.");
1798 return;
1799 }
1800
1801 while (map->l_prev != NULL)
1802 map = map->l_prev;
1803
1804 while (map != NULL) {
1805 st->print_cr(PTR_FORMAT " \t%s", map->l_addr, map->l_name);
1806 map = map->l_next;
1807 }
1808
1809 dlclose(handle);
1810 }
1811
1812 int os::get_loaded_modules_info(os::LoadedModulesCallbackFunc callback, void *param) {
1813 Dl_info dli;
1814 // Sanity check?
1815 if (dladdr(CAST_FROM_FN_PTR(void *, os::get_loaded_modules_info), &dli) == 0 ||
1816 dli.dli_fname == NULL) {
1817 return 1;
1818 }
1819
1820 void * handle = dlopen(dli.dli_fname, RTLD_LAZY);
1821 if (handle == NULL) {
1822 return 1;
1823 }
1824
1825 Link_map *map;
1826 dlinfo(handle, RTLD_DI_LINKMAP, &map);
1827 if (map == NULL) {
1828 dlclose(handle);
1829 return 1;
1830 }
1831
1832 while (map->l_prev != NULL) {
1833 map = map->l_prev;
1834 }
1835
1836 while (map != NULL) {
1837 // Iterate through all map entries and call callback with fields of interest
1838 if(callback(map->l_name, (address)map->l_addr, (address)0, param)) {
1839 dlclose(handle);
1840 return 1;
1841 }
1842 map = map->l_next;
1843 }
1844
1845 dlclose(handle);
1846 return 0;
1847 }
1848
1849 // Loads .dll/.so and
1850 // in case of error it checks if .dll/.so was built for the
1851 // same architecture as Hotspot is running on
1852
1853 void * os::dll_load(const char *filename, char *ebuf, int ebuflen)
1854 {
1855 void * result= ::dlopen(filename, RTLD_LAZY);
1856 if (result != NULL) {
1857 // Successful loading
1858 return result;
1859 }
1860
1861 Elf32_Ehdr elf_head;
1862
1863 // Read system error message into ebuf
1864 // It may or may not be overwritten below
1865 ::strncpy(ebuf, ::dlerror(), ebuflen-1);
1866 ebuf[ebuflen-1]='\0';
1867 int diag_msg_max_length=ebuflen-strlen(ebuf);
1868 char* diag_msg_buf=ebuf+strlen(ebuf);
3271 assert(newtime >= prevtime, "time moving backwards");
3272 /* Doing prevtime and newtime in microseconds doesn't help precision,
3273 and trying to round up to avoid lost milliseconds can result in a
3274 too-short delay. */
3275 millis -= newtime - prevtime;
3276 if(millis <= 0)
3277 return OS_OK;
3278 prevtime = newtime;
3279 } else
3280 return res;
3281 }
3282
3283 return OS_OK;
3284 }
3285
3286 // Read calls from inside the vm need to perform state transitions
3287 size_t os::read(int fd, void *buf, unsigned int nBytes) {
3288 INTERRUPTIBLE_RETURN_INT_VM(::read(fd, buf, nBytes), os::Solaris::clear_interrupted);
3289 }
3290
3291 size_t os::read_at(int fd, void *buf, unsigned int nBytes, jlong offset) {
3292 size_t res;
3293 JavaThread* thread = (JavaThread*)Thread::current();
3294 assert(thread->thread_state() == _thread_in_vm, "Assumed _thread_in_vm");
3295 ThreadBlockInVM tbiv(thread);
3296 RESTARTABLE(::pread(fd, buf, (size_t) nBytes, offset), res);
3297 return res;
3298 }
3299
3300 size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
3301 INTERRUPTIBLE_RETURN_INT(::read(fd, buf, nBytes), os::Solaris::clear_interrupted);
3302 }
3303
3304 int os::sleep(Thread* thread, jlong millis, bool interruptible) {
3305 assert(thread == Thread::current(), "thread consistency check");
3306
3307 // TODO-FIXME: this should be removed.
3308 // On Solaris machines (especially 2.5.1) we found that sometimes the VM gets into a live lock
3309 // situation with a JavaThread being starved out of a lwp. The kernel doesn't seem to generate
3310 // a SIGWAITING signal which would enable the threads library to create a new lwp for the starving
3311 // thread. We suspect that because the Watcher thread keeps waking up at periodic intervals the kernel
3312 // is fooled into believing that the system is making progress. In the code below we block the
3313 // the watcher thread while safepoint is in progress so that it would not appear as though the
3314 // system is making progress.
3315 if (!Solaris::T2_libthread() &&
3316 thread->is_Watcher_thread() && SafepointSynchronize::is_synchronizing() && !Arguments::has_profile()) {
3317 // We now try to acquire the threads lock. Since this lock is held by the VM thread during
3318 // the entire safepoint, the watcher thread will line up here during the safepoint.
3319 Threads_lock->lock_without_safepoint_check();
5177 where = RTLD_DEFAULT;
5178 if ((sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "__vsnprintf"))) == NULL)
5179 sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "vsnprintf"));
5180 assert(sol_vsnprintf != NULL, "vsnprintf not found");
5181 }
5182 }
5183 return (*sol_vsnprintf)(buf, count, fmt, argptr);
5184 }
5185
5186
5187 // Is a (classpath) directory empty?
5188 bool os::dir_is_empty(const char* path) {
5189 DIR *dir = NULL;
5190 struct dirent *ptr;
5191
5192 dir = opendir(path);
5193 if (dir == NULL) return true;
5194
5195 /* Scan the directory */
5196 bool result = true;
5197 while (result && (ptr = readdir(dirf)) != NULL) {
5198 if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
5199 result = false;
5200 }
5201 }
5202 closedir(dir);
5203 return result;
5204 }
5205
5206 // This code originates from JDK's sysOpen and open64_w
5207 // from src/solaris/hpi/src/system_md.c
5208
5209 #ifndef O_DELETE
5210 #define O_DELETE 0x10000
5211 #endif
5212
5213 // Open a file. Unlink the file immediately after open returns
5214 // if the specified oflag has the O_DELETE flag set.
5215 // O_DELETE is used only in j2se/src/share/native/java/util/zip/ZipFile.c
5216
5217 int os::open(const char *path, int oflag, int mode) {
|