1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
283
284
285 JVM_LEAF(jint, JVM_GetInterfaceVersion())
286 return JVM_INTERFACE_VERSION;
287 JVM_END
288
289
290 // java.lang.System //////////////////////////////////////////////////////////////////////
291
292
293 JVM_LEAF(jlong, JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored))
294 JVMWrapper("JVM_CurrentTimeMillis");
295 return os::javaTimeMillis();
296 JVM_END
297
298 JVM_LEAF(jlong, JVM_NanoTime(JNIEnv *env, jclass ignored))
299 JVMWrapper("JVM_NanoTime");
300 return os::javaTimeNanos();
301 JVM_END
302
303
304 JVM_ENTRY(void, JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos,
305 jobject dst, jint dst_pos, jint length))
306 JVMWrapper("JVM_ArrayCopy");
307 // Check if we have null pointers
308 if (src == NULL || dst == NULL) {
309 THROW(vmSymbols::java_lang_NullPointerException());
310 }
311 arrayOop s = arrayOop(JNIHandles::resolve_non_null(src));
312 arrayOop d = arrayOop(JNIHandles::resolve_non_null(dst));
313 assert(s->is_oop(), "JVM_ArrayCopy: src not an oop");
314 assert(d->is_oop(), "JVM_ArrayCopy: dst not an oop");
315 // Do copy
316 s->klass()->copy_array(s, src_pos, d, dst_pos, length, thread);
317 JVM_END
318
319
320 static void set_property(Handle props, const char* key, const char* value, TRAPS) {
321 JavaValue r(T_OBJECT);
322 // public synchronized Object put(Object key, Object value);
|
1 /*
2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
283
284
285 JVM_LEAF(jint, JVM_GetInterfaceVersion())
286 return JVM_INTERFACE_VERSION;
287 JVM_END
288
289
290 // java.lang.System //////////////////////////////////////////////////////////////////////
291
292
293 JVM_LEAF(jlong, JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored))
294 JVMWrapper("JVM_CurrentTimeMillis");
295 return os::javaTimeMillis();
296 JVM_END
297
298 JVM_LEAF(jlong, JVM_NanoTime(JNIEnv *env, jclass ignored))
299 JVMWrapper("JVM_NanoTime");
300 return os::javaTimeNanos();
301 JVM_END
302
303 // The function below is actually exposed by sun.misc.VM and not
304 // java.lang.System, but we choose to keep it here so that it stays next
305 // to JVM_CurrentTimeMillis and JVM_NanoTime
306
307 const jlong MAX_DIFF_SECS = 0x0100000000; // 2^32
308 const jlong MIN_DIFF_SECS = -MAX_DIFF_SECS; // -2^32
309
310 JVM_LEAF(jlong, JVM_GetNanoTimeAdjustment(JNIEnv *env, jclass ignored, jlong offset_secs))
311 JVMWrapper("JVM_GetNanoTimeAdjustment");
312 jlong seconds;
313 jlong nanos;
314
315 os::javaTimeSystemUTC(seconds, nanos);
316
317 // We're going to verify that the result can fit in a long.
318 // For that we need the difference in seconds between 'seconds'
319 // and 'offset_secs' to be such that:
320 // |seconds - offset_secs| < (2^63/10^9)
321 // We're going to approximate 10^9 ~< 2^30 (1000^3 ~< 1024^3)
322 // which makes |seconds - offset_secs| < 2^33
323 // and we will prefer +/- 2^32 as the maximum acceptable diff
324 // as 2^32 has a more natural feel than 2^33...
325 //
326 // So if |seconds - offset_secs| >= 2^32 - we return a special
327 // sentinel value (-1) which the caller should take as an
328 // exception value indicating that the offset given to us is
329 // too far from range of the current time - leading to too big
330 // a nano adjustment. The caller is expected to recover by
331 // computing a more accurate offset and calling this method
332 // again. (For the record 2^32 secs is ~136 years, so that
333 // should rarely happen)
334 //
335 jlong diff = seconds - offset_secs;
336 if (diff >= MAX_DIFF_SECS || diff <= MIN_DIFF_SECS) {
337 return -1; // sentinel value: the offset is too far off the target
338 }
339
340 // return the adjustment. If you compute a time by adding
341 // this number of nanoseconds along with the number of seconds
342 // in the offset you should get the current UTC time.
343 return (diff * (jlong)1000000000) + nanos;
344 JVM_END
345
346 JVM_ENTRY(void, JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos,
347 jobject dst, jint dst_pos, jint length))
348 JVMWrapper("JVM_ArrayCopy");
349 // Check if we have null pointers
350 if (src == NULL || dst == NULL) {
351 THROW(vmSymbols::java_lang_NullPointerException());
352 }
353 arrayOop s = arrayOop(JNIHandles::resolve_non_null(src));
354 arrayOop d = arrayOop(JNIHandles::resolve_non_null(dst));
355 assert(s->is_oop(), "JVM_ArrayCopy: src not an oop");
356 assert(d->is_oop(), "JVM_ArrayCopy: dst not an oop");
357 // Do copy
358 s->klass()->copy_array(s, src_pos, d, dst_pos, length, thread);
359 JVM_END
360
361
362 static void set_property(Handle props, const char* key, const char* value, TRAPS) {
363 JavaValue r(T_OBJECT);
364 // public synchronized Object put(Object key, Object value);
|