Skip to content

Commit

Permalink
Merge pull request ibmruntimes#526 from JasonFengJ9/mergetmp
Browse files Browse the repository at this point in the history
Merge master HEAD into openj9-staging
  • Loading branch information
keithc-ca authored Dec 1, 2022
2 parents 6cd9c20 + 494f798 commit 685fd3f
Show file tree
Hide file tree
Showing 97 changed files with 1,611 additions and 1,563 deletions.
49 changes: 48 additions & 1 deletion doc/hotspot-style.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ <h1 class="title">HotSpot Coding Style</h1>
<li><a href="#expression-sfinae" id="toc-expression-sfinae">Expression
SFINAE</a></li>
<li><a href="#enum" id="toc-enum">enum</a></li>
<li><a href="#alignas" id="toc-alignas">alignas</a></li>
<li><a href="#thread_local" id="toc-thread_local">thread_local</a></li>
<li><a href="#nullptr" id="toc-nullptr">nullptr</a></li>
<li><a href="#atomic" id="toc-atomic">&lt;atomic&gt;</a></li>
Expand Down Expand Up @@ -598,7 +599,7 @@ <h3 id="c-standard-library">C++ Standard Library</h3>
<code>std::numeric_limits</code>.</li>
<li><code>#include &lt;type_traits&gt;</code>.</li>
<li><code>#include &lt;cstddef&gt;</code> to use
<code>std::nullptr_t</code>.</li>
<code>std::nullptr_t</code> and <code>std::max_align_t</code>.</li>
</ul>
<p>TODO: Rather than directly #including (permitted) Standard Library
headers, use a convention of #including wrapper headers (in some
Expand Down Expand Up @@ -670,6 +671,52 @@ <h3 id="enum">enum</h3>
constant members. Compilers having such bugs are no longer supported.
Except where an enum is semantically appropriate, new code should use
integral constants.</p>
<h3 id="alignas">alignas</h3>
<p><em>Alignment-specifiers</em> (<code>alignas</code> <a
href="https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2341.pdf">n2341</a>)
are permitted, with restrictions.</p>
<p><em>Alignment-specifiers</em> are permitted when the requested
alignment is a <em>fundamental alignment</em> (not greater than
<code>alignof(std::max_align_t)</code> <a
href="https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf">C++14
3.11/2</a>).</p>
<p><em>Alignment-specifiers</em> with an <em>extended alignment</em>
(greater than <code>alignof(std::max_align_t)</code> <a
href="https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf">C++14
3.11/3</a>) may only be used to align variables with static or automatic
storage duration (<a
href="https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf">C++14
3.7.1, 3.7.3</a>). As a consequence, <em>over-aligned types</em> are
forbidden; this may change if HotSpot updates to using C++17 or later <a
href="https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0035r4.html">p0035r4</a>.</p>
<p>Large <em>extended alignments</em> should be avoided, particularly
for stack allocated objects. What is a large value may depend on the
platform and configuration. There may also be hard limits for some
platforms.</p>
<p>An <em>alignment-specifier</em> must always be applied to a
definition (<a
href="https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf">C++14
10.6.2/6</a>). (C++ allows an <em>alignment-specifier</em> to optionally
also be applied to a declaration, so long as the definition has
equivalent alignment. There isn't any known benefit from duplicating the
alignment in a non-definition declaration, so such duplication should be
avoided in HotSpot code.)</p>
<p>Enumerations are forbidden from having <em>alignment-specifiers</em>.
Aligned enumerations were originally permitted but insufficiently
specified, and were later (C++20) removed <a
href="https://cplusplus.github.io/CWG/issues/2354.html">CWG 2354</a>.
Permitting such usage in HotSpot now would just cause problems in the
future.</p>
<p><em>Alignment-specifiers</em> are forbidden in <code>typedef</code>
and <em>alias-declarations</em>. This may work or may have worked in
some versions of some compilers, but was later (C++14) explicitly
disallowed <a
href="https://cplusplus.github.io/CWG/issues/1437.html">CWG
1437</a>.</p>
<p>The HotSpot macro <code>ATTRIBUTE_ALIGNED</code> provides similar
capabilities for platforms that define it. This macro predates the use
by HotSpot of C++ versions providing <code>alignas</code>. New code
should use <code>alignas</code>.</p>
<h3 id="thread_local">thread_local</h3>
<p>Avoid use of <code>thread_local</code> (<a
href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2659.htm">n2659</a>);
Expand Down
47 changes: 46 additions & 1 deletion doc/hotspot-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ There are a few exceptions to this rule.
* `#include <new>` to use placement `new`, `std::nothrow`, and `std::nothrow_t`.
* `#include <limits>` to use `std::numeric_limits`.
* `#include <type_traits>`.
* `#include <cstddef>` to use `std::nullptr_t`.
* `#include <cstddef>` to use `std::nullptr_t` and `std::max_align_t`.

TODO: Rather than directly \#including (permitted) Standard Library
headers, use a convention of \#including wrapper headers (in some
Expand Down Expand Up @@ -651,6 +651,51 @@ constant members. Compilers having such bugs are no longer supported.
Except where an enum is semantically appropriate, new code should use
integral constants.

### alignas

_Alignment-specifiers_ (`alignas`
[n2341](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2341.pdf))
are permitted, with restrictions.

_Alignment-specifiers_ are permitted when the requested alignment is a
_fundamental alignment_ (not greater than `alignof(std::max_align_t)`
[C++14 3.11/2](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf)).

_Alignment-specifiers_ with an _extended alignment_ (greater than
`alignof(std::max_align_t)`
[C++14 3.11/3](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf))
may only be used to align variables with static or automatic storage duration
([C++14 3.7.1, 3.7.3](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf)).
As a consequence, _over-aligned types_ are forbidden; this may change if
HotSpot updates to using C++17 or later
[p0035r4](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0035r4.html).

Large _extended alignments_ should be avoided, particularly for stack
allocated objects. What is a large value may depend on the platform and
configuration. There may also be hard limits for some platforms.

An _alignment-specifier_ must always be applied to a definition
([C++14 10.6.2/6](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf)).
(C++ allows an _alignment-specifier_ to optionally also be applied to a
declaration, so long as the definition has equivalent alignment. There isn't
any known benefit from duplicating the alignment in a non-definition
declaration, so such duplication should be avoided in HotSpot code.)

Enumerations are forbidden from having _alignment-specifiers_. Aligned
enumerations were originally permitted but insufficiently specified, and were
later (C++20) removed
[CWG 2354](https://cplusplus.github.io/CWG/issues/2354.html).
Permitting such usage in HotSpot now would just cause problems in the future.

_Alignment-specifiers_ are forbidden in `typedef` and _alias-declarations_.
This may work or may have worked in some versions of some compilers, but was
later (C++14) explicitly disallowed
[CWG 1437](https://cplusplus.github.io/CWG/issues/1437.html).

The HotSpot macro `ATTRIBUTE_ALIGNED` provides similar capabilities for
platforms that define it. This macro predates the use by HotSpot of C++
versions providing `alignas`. New code should use `alignas`.

### thread_local

Avoid use of `thread_local`
Expand Down
23 changes: 13 additions & 10 deletions src/java.base/share/classes/java/lang/invoke/LambdaForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ boolean contains(Name name) {
static class NamedFunction {
final MemberName member;
private @Stable MethodHandle resolvedHandle;
@Stable MethodHandle invoker;
private @Stable MethodType type;

NamedFunction(MethodHandle resolvedHandle) {
this(resolvedHandle.internalMemberName(), resolvedHandle);
Expand Down Expand Up @@ -1185,10 +1185,6 @@ Object invokeWithArgumentsTracing(Object[] arguments) throws Throwable {
Object rval;
try {
traceInterpreter("[ call", this, arguments);
if (invoker == null) {
traceInterpreter("| getInvoker", this);
invoker();
}
// resolvedHandle might be uninitialized, ok for tracing
if (resolvedHandle == null) {
traceInterpreter("| resolve", this);
Expand All @@ -1204,17 +1200,24 @@ Object invokeWithArgumentsTracing(Object[] arguments) throws Throwable {
}

private MethodHandle invoker() {
if (invoker != null) return invoker;
// Get an invoker and cache it.
return invoker = computeInvoker(methodType().form());
return computeInvoker(methodType().form());
}

MethodType methodType() {
if (resolvedHandle != null)
MethodType type = this.type;
if (type == null) {
this.type = type = calculateMethodType(member, resolvedHandle);
}
return type;
}

private static MethodType calculateMethodType(MemberName member, MethodHandle resolvedHandle) {
if (resolvedHandle != null) {
return resolvedHandle.type();
else
} else {
// only for certain internal LFs during bootstrapping
return member.getInvocationType();
}
}

MemberName member() {
Expand Down
13 changes: 5 additions & 8 deletions src/java.base/share/classes/java/math/MutableBigInteger.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -1531,13 +1531,10 @@ private MutableBigInteger divideMagnitude(MutableBigInteger div,
quotient.intLen = limit;
int[] q = quotient.value;


// Must insert leading 0 in rem if its length did not change
if (rem.intLen == nlen) {
rem.offset = 0;
rem.value[0] = 0;
rem.intLen++;
}
// Insert leading 0 in rem
rem.offset = 0;
rem.value[0] = 0;
rem.intLen++;

int dh = divisor[0];
long dhLong = dh & LONG_MASK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1999,8 +1999,8 @@ private InputStream getInputStream0() throws IOException {
return inputStream;
} while (redirects < maxRedirects);

throw new ProtocolException("Server redirected too many " +
" times ("+ redirects + ")");
throw new ProtocolException("Server redirected too many times (" +
redirects + ")");
} catch (RuntimeException e) {
disconnectInternal();
rememberedException = e;
Expand Down
15 changes: 8 additions & 7 deletions src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,16 @@ - (BOOL) checkPasteboardWithoutNotification:(id)application {
jint nElements = (*env)->GetArrayLength(env, inTypes);
NSMutableArray *formatArray = [NSMutableArray arrayWithCapacity:nElements];
jlong *elements = (*env)->GetPrimitiveArrayCritical(env, inTypes, NULL);
if (elements != NULL) {
for (i = 0; i < nElements; i++) {
NSString *pbFormat = formatForIndex(elements[i]);
if (pbFormat)
[formatArray addObject:pbFormat];
}

for (i = 0; i < nElements; i++) {
NSString *pbFormat = formatForIndex(elements[i]);
if (pbFormat)
[formatArray addObject:pbFormat];
(*env)->ReleasePrimitiveArrayCritical(env, inTypes, elements, JNI_ABORT);
[[CClipboard sharedClipboard] declareTypes:formatArray withOwner:inJavaClip jniEnv:env];
}

(*env)->ReleasePrimitiveArrayCritical(env, inTypes, elements, JNI_ABORT);
[[CClipboard sharedClipboard] declareTypes:formatArray withOwner:inJavaClip jniEnv:env];
JNI_COCOA_EXIT(env);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@
{
jint *glyphCodeInts = (*env)->GetPrimitiveArrayCritical(env, glyphs, 0);

CTS_GetGlyphsAsIntsForCharacters(awtFont, unicodes,
cgGlyphs, glyphCodeInts, count);
if (glyphCodeInts != NULL) {
CTS_GetGlyphsAsIntsForCharacters(awtFont, unicodes,
cgGlyphs, glyphCodeInts, count);

// Do not use JNI_COMMIT, as that will not free the buffer copy
// when +ProtectJavaHeap is on.
(*env)->ReleasePrimitiveArrayCritical(env, glyphs, glyphCodeInts, 0);
// Do not use JNI_COMMIT, as that will not free the buffer copy
// when +ProtectJavaHeap is on.
(*env)->ReleasePrimitiveArrayCritical(env, glyphs, glyphCodeInts, 0);
}
}

static inline void
Expand Down
12 changes: 7 additions & 5 deletions src/java.desktop/macosx/native/libosxui/JRSUIController.m
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,13 @@ static inline jint doPaintCGContext(CGContextRef cgRef, jlong controlPtr, jlong
CGRect partBounds = JRSUIControlGetScrollBarPartBounds(control, frame, part);

jdouble *rect = (*env)->GetPrimitiveArrayCritical(env, rectArray, NULL);
rect[0] = partBounds.origin.x;
rect[1] = partBounds.origin.y;
rect[2] = partBounds.size.width;
rect[3] = partBounds.size.height;
(*env)->ReleasePrimitiveArrayCritical(env, rectArray, rect, 0);
if (rect != NULL) {
rect[0] = partBounds.origin.x;
rect[1] = partBounds.origin.y;
rect[2] = partBounds.size.width;
rect[3] = partBounds.size.height;
(*env)->ReleasePrimitiveArrayCritical(env, rectArray, rect, 0);
}
}

/*
Expand Down
16 changes: 8 additions & 8 deletions src/java.desktop/share/classes/java/awt/image/DataBuffer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -35,13 +35,13 @@

package java.awt.image;

import sun.java2d.StateTrackable.State;
import static sun.java2d.StateTrackable.State.*;
import sun.java2d.StateTrackableDelegate;
import java.lang.annotation.Native;

import sun.awt.image.SunWritableRaster;
import sun.java2d.StateTrackable.State;
import sun.java2d.StateTrackableDelegate;

import java.lang.annotation.Native;
import static sun.java2d.StateTrackable.State.UNTRACKABLE;

/**
* This class exists to wrap one or more data arrays. Each data array in
Expand Down Expand Up @@ -75,16 +75,16 @@ public abstract class DataBuffer {
/** Tag for unsigned short data. */
@Native public static final int TYPE_USHORT = 1;

/** Tag for signed short data. Placeholder for future use. */
/** Tag for signed short data. */
@Native public static final int TYPE_SHORT = 2;

/** Tag for int data. */
@Native public static final int TYPE_INT = 3;

/** Tag for float data. Placeholder for future use. */
/** Tag for float data. */
@Native public static final int TYPE_FLOAT = 4;

/** Tag for double data. Placeholder for future use. */
/** Tag for double data. */
@Native public static final int TYPE_DOUBLE = 5;

/** Tag for undefined data. */
Expand Down
38 changes: 23 additions & 15 deletions src/java.desktop/share/classes/javax/swing/JPasswordField.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -36,8 +36,10 @@
import javax.accessibility.AccessibleRole;
import javax.accessibility.AccessibleText;
import javax.accessibility.AccessibleTextSequence;
import javax.swing.text.AbstractDocument;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.DocumentFilter;
import javax.swing.text.Segment;

/**
Expand Down Expand Up @@ -300,21 +302,27 @@ public String getText(int offs, int len) throws BadLocationException {
public void setText(String t) {
// overwrite the old data first
Document doc = getDocument();
int nleft = doc.getLength();
Segment text = new Segment();
// we would like to get direct data array access, not a copy of it
text.setPartialReturn(true);
int offs = 0;
try {
while (nleft > 0) {
doc.getText(offs, nleft, text);
Arrays.fill(text.array, text.offset,
text.count + text.offset, '\u0000');
nleft -= text.count;
offs += text.count;
DocumentFilter filter = null;
if (doc instanceof AbstractDocument adoc) {
filter = adoc.getDocumentFilter();
}
if (filter == null) {
int nleft = doc.getLength();
Segment text = new Segment();
// we would like to get direct data array access, not a copy of it
text.setPartialReturn(true);
int offs = 0;
try {
while (nleft > 0) {
doc.getText(offs, nleft, text);
Arrays.fill(text.array, text.offset,
text.count + text.offset, '\u0000');
nleft -= text.count;
offs += text.count;
}
} catch (BadLocationException ignored) {
// we tried
}
} catch (BadLocationException ignored) {
// we tried
}
super.setText(t);
}
Expand Down
Loading

0 comments on commit 685fd3f

Please sign in to comment.