Skip to content

Commit c096c77

Browse files
committed
Merge branch 'master' into topic/GR-21836
2 parents baed442 + b014624 commit c096c77

73 files changed

Lines changed: 1711 additions & 375 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎ci.jsonnet‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "overlay": "b71a364c7c59a8205b0e40c4e6b6918164ed01a7" }
1+
{ "overlay": "d521478b3a031b5b55bb1b629650320cc9c9d425" }
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3+
#
4+
# The Universal Permissive License (UPL), Version 1.0
5+
#
6+
# Subject to the condition set forth below, permission is hereby granted to any
7+
# person obtaining a copy of this software, associated documentation and/or
8+
# data (collectively the "Software"), free of charge and under any and all
9+
# copyright rights in the Software, and any and all patent rights owned or
10+
# freely licensable by each licensor hereunder covering either (i) the
11+
# unmodified Software as contributed to or provided by such licensor, or (ii)
12+
# the Larger Works (as defined below), to deal in both
13+
#
14+
# (a) the Software, and
15+
#
16+
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
17+
# one is included with the Software each a "Larger Work" to which the Software
18+
# is contributed by such licensors),
19+
#
20+
# without restriction, including without limitation the rights to copy, create
21+
# derivative works of, display, perform, and distribute the Software and make,
22+
# use, sell, offer for sale, import, export, have made, and have sold the
23+
# Software and the Larger Work(s), and to sublicense the foregoing rights on
24+
# either these or other terms.
25+
#
26+
# This license is subject to the following condition:
27+
#
28+
# The above copyright notice and either this complete permission notice or at a
29+
# minimum a reference to the UPL must be included in all copies or substantial
30+
# portions of the Software.
31+
#
32+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38+
# SOFTWARE.
39+
40+
41+
def count(num):
42+
cnt = 0
43+
for i in range(num):
44+
try:
45+
if i % 2:
46+
raise ValueError
47+
except Exception:
48+
cnt += 1
49+
50+
return cnt
51+
52+
53+
def measure(num):
54+
result = count(num)
55+
print("last value: %s " % result)
56+
57+
58+
def __benchmark__(num=1000000):
59+
measure(num)
60+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3+
#
4+
# The Universal Permissive License (UPL), Version 1.0
5+
#
6+
# Subject to the condition set forth below, permission is hereby granted to any
7+
# person obtaining a copy of this software, associated documentation and/or
8+
# data (collectively the "Software"), free of charge and under any and all
9+
# copyright rights in the Software, and any and all patent rights owned or
10+
# freely licensable by each licensor hereunder covering either (i) the
11+
# unmodified Software as contributed to or provided by such licensor, or (ii)
12+
# the Larger Works (as defined below), to deal in both
13+
#
14+
# (a) the Software, and
15+
#
16+
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
17+
# one is included with the Software each a "Larger Work" to which the Software
18+
# is contributed by such licensors),
19+
#
20+
# without restriction, including without limitation the rights to copy, create
21+
# derivative works of, display, perform, and distribute the Software and make,
22+
# use, sell, offer for sale, import, export, have made, and have sold the
23+
# Software and the Larger Work(s), and to sublicense the foregoing rights on
24+
# either these or other terms.
25+
#
26+
# This license is subject to the following condition:
27+
#
28+
# The above copyright notice and either this complete permission notice or at a
29+
# minimum a reference to the UPL must be included in all copies or substantial
30+
# portions of the Software.
31+
#
32+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38+
# SOFTWARE.
39+
40+
41+
def count(num):
42+
cnt = 0
43+
for i in range(num):
44+
try:
45+
if i % 2:
46+
raise ValueError
47+
except Exception as e:
48+
cnt += 1
49+
50+
return cnt
51+
52+
53+
def measure(num):
54+
result = count(num)
55+
print("last value: %s " % result)
56+
57+
58+
def __benchmark__(num=1000000):
59+
measure(num)
60+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3+
#
4+
# The Universal Permissive License (UPL), Version 1.0
5+
#
6+
# Subject to the condition set forth below, permission is hereby granted to any
7+
# person obtaining a copy of this software, associated documentation and/or
8+
# data (collectively the "Software"), free of charge and under any and all
9+
# copyright rights in the Software, and any and all patent rights owned or
10+
# freely licensable by each licensor hereunder covering either (i) the
11+
# unmodified Software as contributed to or provided by such licensor, or (ii)
12+
# the Larger Works (as defined below), to deal in both
13+
#
14+
# (a) the Software, and
15+
#
16+
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
17+
# one is included with the Software each a "Larger Work" to which the Software
18+
# is contributed by such licensors),
19+
#
20+
# without restriction, including without limitation the rights to copy, create
21+
# derivative works of, display, perform, and distribute the Software and make,
22+
# use, sell, offer for sale, import, export, have made, and have sold the
23+
# Software and the Larger Work(s), and to sublicense the foregoing rights on
24+
# either these or other terms.
25+
#
26+
# This license is subject to the following condition:
27+
#
28+
# The above copyright notice and either this complete permission notice or at a
29+
# minimum a reference to the UPL must be included in all copies or substantial
30+
# portions of the Software.
31+
#
32+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38+
# SOFTWARE.
39+
40+
41+
def count(num):
42+
cnt = 0
43+
for i in range(num):
44+
try:
45+
if i % 2:
46+
raise ValueError
47+
if i % 3:
48+
raise ArithmeticError("1")
49+
except Exception as e:
50+
cnt += 1
51+
52+
return cnt
53+
54+
55+
def measure(num):
56+
result = count(num)
57+
print("last value: %s " % result)
58+
59+
60+
def __benchmark__(num=1000000):
61+
measure(num)
62+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3+
#
4+
# The Universal Permissive License (UPL), Version 1.0
5+
#
6+
# Subject to the condition set forth below, permission is hereby granted to any
7+
# person obtaining a copy of this software, associated documentation and/or
8+
# data (collectively the "Software"), free of charge and under any and all
9+
# copyright rights in the Software, and any and all patent rights owned or
10+
# freely licensable by each licensor hereunder covering either (i) the
11+
# unmodified Software as contributed to or provided by such licensor, or (ii)
12+
# the Larger Works (as defined below), to deal in both
13+
#
14+
# (a) the Software, and
15+
#
16+
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
17+
# one is included with the Software each a "Larger Work" to which the Software
18+
# is contributed by such licensors),
19+
#
20+
# without restriction, including without limitation the rights to copy, create
21+
# derivative works of, display, perform, and distribute the Software and make,
22+
# use, sell, offer for sale, import, export, have made, and have sold the
23+
# Software and the Larger Work(s), and to sublicense the foregoing rights on
24+
# either these or other terms.
25+
#
26+
# This license is subject to the following condition:
27+
#
28+
# The above copyright notice and either this complete permission notice or at a
29+
# minimum a reference to the UPL must be included in all copies or substantial
30+
# portions of the Software.
31+
#
32+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38+
# SOFTWARE.
39+
40+
41+
def count(num):
42+
cnt = 0
43+
for i in range(num):
44+
try:
45+
if i % 2:
46+
raise ValueError
47+
if i % 3:
48+
raise ArithmeticError("1")
49+
except Exception:
50+
cnt += 1
51+
52+
return cnt
53+
54+
55+
def measure(num):
56+
result = count(num)
57+
print("last value: %s " % result)
58+
59+
60+
def __benchmark__(num=1000000):
61+
measure(num)
62+

‎graalpython/com.oracle.graal.python.cext/include/longintrepr.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2018, 2019, Oracle and/or its affiliates.
1+
/* Copyright (c) 2018, 2020, Oracle and/or its affiliates.
22
* Copyright (C) 1996-2017 Python Software Foundation
33
*
44
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -89,7 +89,8 @@ typedef long stwodigits; /* signed variant of twodigits */
8989

9090
struct _longobject {
9191
PyObject_VAR_HEAD
92-
digit ob_digit[1];
92+
digit dummy;
93+
digit ob_digit[];
9394
};
9495

9596
PyAPI_FUNC(PyLongObject *) _PyLong_New(Py_ssize_t);

‎graalpython/com.oracle.graal.python.cext/setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import _sysconfig
4848

4949
__dir__ = __file__.rpartition("/")[0]
50-
cflags_warnings = ["-Wno-int-to-pointer-cast", "-Wno-int-conversion", "-Wno-incompatible-pointer-types-discards-qualifiers", "-Wno-pointer-type-mismatch"]
50+
cflags_warnings = ["-Wno-int-to-pointer-cast", "-Wno-int-conversion", "-Wno-incompatible-pointer-types-discards-qualifiers", "-Wno-pointer-type-mismatch", "-Wno-braced-scalar-init"]
5151
libpython_name = "libpython"
5252

5353
verbosity = '--verbose' if sys.flags.verbose else '--quiet'

‎graalpython/com.oracle.graal.python.cext/src/capi.c‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ uint32_t Py_Truffle_Options;
6363
cache_t cache;
6464
ptr_cache_t ptr_cache;
6565
ptr_cache_t ptr_cache_stealing;
66+
type_ptr_cache_t type_ptr_cache;
6667

6768
alloc_upcall_fun_t alloc_upcall;
6869
free_upcall_fun_t free_upcall;
@@ -95,9 +96,10 @@ static void initialize_upcall_functions() {
9596

9697
__attribute__((constructor (__COUNTER__)))
9798
static void initialize_handle_cache() {
98-
cache = (cache_t)polyglot_invoke(PY_TRUFFLE_CEXT, "PyTruffle_HandleCache_Create", truffle_managed_from_handle);
99-
ptr_cache = (ptr_cache_t)polyglot_invoke(PY_TRUFFLE_CEXT, "PyTruffle_PtrCache_Create", 0);
100-
ptr_cache_stealing = (ptr_cache_t)polyglot_invoke(PY_TRUFFLE_CEXT, "PyTruffle_PtrCache_Create", 1);
99+
cache = (cache_t) polyglot_invoke(PY_TRUFFLE_CEXT, "PyTruffle_HandleCache_Create", truffle_managed_from_handle);
100+
ptr_cache = (ptr_cache_t) polyglot_invoke(PY_TRUFFLE_CEXT, "PyTruffle_PtrCache_Create", 0);
101+
ptr_cache_stealing = (ptr_cache_t) polyglot_invoke(PY_TRUFFLE_CEXT, "PyTruffle_PtrCache_Create", 1);
102+
type_ptr_cache = (type_ptr_cache_t) polyglot_invoke(PY_TRUFFLE_CEXT, "PyTruffle_PtrCache_Create", 0);
101103
}
102104

103105
void initialize_type_structure(PyTypeObject* structure, PyTypeObject* ptype, polyglot_typeid tid) {
@@ -312,7 +314,7 @@ PyObject* get_tp_name(PyTypeObject* obj) {
312314

313315
/** to be used from Java code only; reads native 'tp_mro' field */
314316
PyObject* get_tp_mro(PyTypeObject* obj) {
315-
return native_to_java_slim(obj->tp_mro);
317+
return native_to_java(obj->tp_mro);
316318
}
317319

318320
/** to be used from Java code only; reads native 'tp_subclasses' field */
@@ -712,3 +714,8 @@ int truffle_ptr_compare(void* x, void* y, int op) {
712714
double truffle_read_ob_fval(PyFloatObject* fobj) {
713715
return fobj->ob_fval;
714716
}
717+
718+
/* called from Java to get number of bits per long digit */
719+
int32_t get_long_bits_in_digit() {
720+
return PYLONG_BITS_IN_DIGIT;
721+
}

‎graalpython/com.oracle.graal.python.cext/src/capi.h‎

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,11 @@ extern void* (*PY_TRUFFLE_CEXT_LANDING_PTR)(void* name, ...);
207207
typedef void* (*cache_t)(uint64_t);
208208
extern cache_t cache;
209209

210-
typedef void* (*ptr_cache_t)(void *, uint64_t);
210+
typedef PyObject* (*ptr_cache_t)(PyObject *);
211+
typedef PyTypeObject* (*type_ptr_cache_t)(PyTypeObject *, int64_t);
211212
extern ptr_cache_t ptr_cache;
212213
extern ptr_cache_t ptr_cache_stealing;
214+
extern type_ptr_cache_t type_ptr_cache;
213215

214216
typedef int (*alloc_upcall_fun_t)(void *, Py_ssize_t);
215217
extern alloc_upcall_fun_t alloc_upcall;
@@ -228,51 +230,31 @@ Py_ssize_t PyTruffle_Type_AddSlots(PyTypeObject* cls, PyObject* slotsTuple);
228230

229231

230232
MUST_INLINE
231-
void* native_to_java(PyObject* obj) {
232-
if (obj == NULL) {
233-
return Py_NoValue;
234-
} else if (obj == Py_None) {
235-
return Py_None;
236-
} else if (polyglot_is_string(obj)) {
237-
return obj;
238-
} else if (!truffle_cannot_be_handle(obj)) {
239-
return resolve_handle(cache, (uint64_t)obj);
233+
PyObject* native_to_java(PyObject* obj) {
234+
if (!truffle_cannot_be_handle(obj)) {
235+
return truffle_managed_from_handle(obj);
240236
}
241-
return ptr_cache(obj, obj->ob_refcnt);
237+
return ptr_cache(obj);
242238
}
243239

244240
MUST_INLINE
245-
void* native_to_java_stealing(PyObject* obj) {
246-
if (obj == NULL) {
247-
return Py_NoValue;
248-
} else if (obj == Py_None) {
249-
return Py_None;
250-
} else if (polyglot_is_string(obj)) {
251-
return obj;
252-
} else if (!truffle_cannot_be_handle(obj)) {
241+
PyObject* native_to_java_stealing(PyObject* obj) {
242+
if (!truffle_cannot_be_handle(obj)) {
253243
return resolve_handle(cache, (uint64_t)obj);
254244
}
255-
return ptr_cache_stealing(obj, obj->ob_refcnt);
245+
return ptr_cache_stealing(obj);
256246
}
257247

258248

259249
extern void* native_to_java_exported(PyObject* obj);
260250
extern void* native_to_java_stealing_exported(PyObject* obj);
261251

262-
MUST_INLINE
263-
void* native_to_java_slim(PyObject* obj) {
264-
if (!truffle_cannot_be_handle(obj)) {
265-
return truffle_managed_from_handle(obj);
266-
}
267-
return ptr_cache(obj, obj != NULL ? obj->ob_refcnt : 0);
268-
}
269-
270252
MUST_INLINE
271253
PyTypeObject* native_type_to_java(PyTypeObject* type) {
272254
if (!truffle_cannot_be_handle(type)) {
273255
return (PyTypeObject *)truffle_managed_from_handle(type);
274256
}
275-
return ptr_cache(type, type->ob_base.ob_base.ob_refcnt);
257+
return type_ptr_cache(type, Py_REFCNT(type));
276258
}
277259

278260
MUST_INLINE

0 commit comments

Comments
 (0)