Skip to content

Commit

Permalink
Merge latest openjdk
Browse files Browse the repository at this point in the history
  • Loading branch information
j9build committed Jul 24, 2024
2 parents 9356ab1 + 285c7e8 commit 62186fe
Show file tree
Hide file tree
Showing 80 changed files with 999 additions and 685 deletions.
7 changes: 0 additions & 7 deletions src/java.base/linux/classes/sun/nio/ch/EPollSelectorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
package sun.nio.ch;

import java.io.IOException;
import java.nio.channels.ClosedSelectorException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.spi.SelectorProvider;
Expand Down Expand Up @@ -92,11 +91,6 @@ class EPollSelectorImpl extends SelectorImpl {
EPoll.ctl(epfd, EPOLL_CTL_ADD, eventfd.efd(), EPOLLIN);
}

private void ensureOpen() {
if (!isOpen())
throw new ClosedSelectorException();
}

@Override
protected int doSelect(Consumer<SelectionKey> action, long timeout)
throws IOException
Expand Down Expand Up @@ -243,7 +237,6 @@ protected void implDereg(SelectionKeyImpl ski) throws IOException {

@Override
public void setEventOps(SelectionKeyImpl ski) {
ensureOpen();
synchronized (updateLock) {
updateKeys.addLast(ski);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
package sun.nio.ch;

import java.io.IOException;
import java.nio.channels.ClosedSelectorException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.spi.SelectorProvider;
Expand Down Expand Up @@ -97,11 +96,6 @@ class KQueueSelectorImpl extends SelectorImpl {
KQueue.register(kqfd, fd0, EVFILT_READ, EV_ADD);
}

private void ensureOpen() {
if (!isOpen())
throw new ClosedSelectorException();
}

@Override
protected int doSelect(Consumer<SelectionKey> action, long timeout)
throws IOException
Expand Down Expand Up @@ -285,7 +279,6 @@ protected void implDereg(SelectionKeyImpl ski) throws IOException {

@Override
public void setEventOps(SelectionKeyImpl ski) {
ensureOpen();
synchronized (updateLock) {
updateKeys.addLast(ski);
}
Expand Down
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/lang/String.java
Original file line number Diff line number Diff line change
Expand Up @@ -2987,7 +2987,7 @@ public String concat(String str) {
if (str.isEmpty()) {
return this;
}
return StringConcatHelper.simpleConcat(this, str);
return StringConcatHelper.doConcat(this, str);
}

/**
Expand Down
229 changes: 100 additions & 129 deletions src/java.base/share/classes/java/lang/StringConcatHelper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2024, 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 @@ -119,91 +119,64 @@ static long mix(long lengthCoder, long value) {
*/
static long mix(long lengthCoder, String value) {
lengthCoder += value.length();
if (value.coder() == String.UTF16) {
if (!value.isLatin1()) {
lengthCoder |= UTF16;
}
return checkOverflow(lengthCoder);
}

/**
* Prepends the stringly representation of boolean value into buffer,
* Prepends constant and the stringly representation of value into buffer,
* given the coder and final index. Index is measured in chars, not in bytes!
*
* @param indexCoder final char index in the buffer, along with coder packed
* into higher bits.
* @param buf buffer to append to
* @param value boolean value to encode
* @param prefix a constant to prepend before value
* @return updated index (coder value retained)
*/
static long prepend(long indexCoder, byte[] buf, boolean value) {
static long prepend(long indexCoder, byte[] buf, boolean value, String prefix) {
int index = (int)indexCoder;
if (indexCoder < UTF16) {
if (value) {
buf[--index] = 'e';
buf[--index] = 'u';
buf[--index] = 'r';
buf[--index] = 't';
index -= 4;
buf[index] = 't';
buf[index + 1] = 'r';
buf[index + 2] = 'u';
buf[index + 3] = 'e';
} else {
buf[--index] = 'e';
buf[--index] = 's';
buf[--index] = 'l';
buf[--index] = 'a';
buf[--index] = 'f';
index -= 5;
buf[index] = 'f';
buf[index + 1] = 'a';
buf[index + 2] = 'l';
buf[index + 3] = 's';
buf[index + 4] = 'e';
}
index -= prefix.length();
prefix.getBytes(buf, index, String.LATIN1);
return index;
} else {
if (value) {
StringUTF16.putChar(buf, --index, 'e');
StringUTF16.putChar(buf, --index, 'u');
StringUTF16.putChar(buf, --index, 'r');
StringUTF16.putChar(buf, --index, 't');
index -= 4;
StringUTF16.putChar(buf, index, 't');
StringUTF16.putChar(buf, index + 1, 'r');
StringUTF16.putChar(buf, index + 2, 'u');
StringUTF16.putChar(buf, index + 3, 'e');
} else {
StringUTF16.putChar(buf, --index, 'e');
StringUTF16.putChar(buf, --index, 's');
StringUTF16.putChar(buf, --index, 'l');
StringUTF16.putChar(buf, --index, 'a');
StringUTF16.putChar(buf, --index, 'f');
index -= 5;
StringUTF16.putChar(buf, index, 'f');
StringUTF16.putChar(buf, index + 1, 'a');
StringUTF16.putChar(buf, index + 2, 'l');
StringUTF16.putChar(buf, index + 3, 's');
StringUTF16.putChar(buf, index + 4, 'e');
}
index -= prefix.length();
prefix.getBytes(buf, index, String.UTF16);
return index | UTF16;
}
}

/**
* Prepends constant and the stringly representation of value into buffer,
* given the coder and final index. Index is measured in chars, not in bytes!
*
* @param indexCoder final char index in the buffer, along with coder packed
* into higher bits.
* @param buf buffer to append to
* @param value boolean value to encode
* @param prefix a constant to prepend before value
* @return updated index (coder value retained)
*/
static long prepend(long indexCoder, byte[] buf, boolean value, String prefix) {
indexCoder = prepend(indexCoder, buf, value);
indexCoder = prepend(indexCoder, buf, prefix);
return indexCoder;
}

/**
* Prepends the stringly representation of char value into buffer,
* given the coder and final index. Index is measured in chars, not in bytes!
*
* @param indexCoder final char index in the buffer, along with coder packed
* into higher bits.
* @param buf buffer to append to
* @param value char value to encode
* @return updated index (coder value retained)
*/
static long prepend(long indexCoder, byte[] buf, char value) {
if (indexCoder < UTF16) {
buf[(int)(--indexCoder)] = (byte) (value & 0xFF);
} else {
StringUTF16.putChar(buf, (int)(--indexCoder), value);
}
return indexCoder;
}

/**
* Prepends constant and the stringly representation of value into buffer,
* given the coder and final index. Index is measured in chars, not in bytes!
Expand All @@ -216,26 +189,17 @@ static long prepend(long indexCoder, byte[] buf, char value) {
* @return updated index (coder value retained)
*/
static long prepend(long indexCoder, byte[] buf, char value, String prefix) {
indexCoder = prepend(indexCoder, buf, value);
indexCoder = prepend(indexCoder, buf, prefix);
return indexCoder;
}

/**
* Prepends the stringly representation of integer value into buffer,
* given the coder and final index. Index is measured in chars, not in bytes!
*
* @param indexCoder final char index in the buffer, along with coder packed
* into higher bits.
* @param buf buffer to append to
* @param value integer value to encode
* @return updated index (coder value retained)
*/
static long prepend(long indexCoder, byte[] buf, int value) {
int index = (int)indexCoder;
if (indexCoder < UTF16) {
return StringLatin1.getChars(value, (int)indexCoder, buf);
buf[--index] = (byte) (value & 0xFF);
index -= prefix.length();
prefix.getBytes(buf, index, String.LATIN1);
return index;
} else {
return StringUTF16.getChars(value, (int)indexCoder, buf) | UTF16;
StringUTF16.putChar(buf, --index, value);
index -= prefix.length();
prefix.getBytes(buf, index, String.UTF16);
return index | UTF16;
}
}

Expand All @@ -251,26 +215,17 @@ static long prepend(long indexCoder, byte[] buf, int value) {
* @return updated index (coder value retained)
*/
static long prepend(long indexCoder, byte[] buf, int value, String prefix) {
indexCoder = prepend(indexCoder, buf, value);
indexCoder = prepend(indexCoder, buf, prefix);
return indexCoder;
}

/**
* Prepends the stringly representation of long value into buffer,
* given the coder and final index. Index is measured in chars, not in bytes!
*
* @param indexCoder final char index in the buffer, along with coder packed
* into higher bits.
* @param buf buffer to append to
* @param value long value to encode
* @return updated index (coder value retained)
*/
static long prepend(long indexCoder, byte[] buf, long value) {
int index = (int)indexCoder;
if (indexCoder < UTF16) {
return StringLatin1.getChars(value, (int)indexCoder, buf);
index = StringLatin1.getChars(value, index, buf);
index -= prefix.length();
prefix.getBytes(buf, index, String.LATIN1);
return index;
} else {
return StringUTF16.getChars(value, (int)indexCoder, buf) | UTF16;
index = StringUTF16.getChars(value, index, buf);
index -= prefix.length();
prefix.getBytes(buf, index, String.UTF16);
return index | UTF16;
}
}

Expand All @@ -286,29 +241,18 @@ static long prepend(long indexCoder, byte[] buf, long value) {
* @return updated index (coder value retained)
*/
static long prepend(long indexCoder, byte[] buf, long value, String prefix) {
indexCoder = prepend(indexCoder, buf, value);
indexCoder = prepend(indexCoder, buf, prefix);
return indexCoder;
}

/**
* Prepends the stringly representation of String value into buffer,
* given the coder and final index. Index is measured in chars, not in bytes!
*
* @param indexCoder final char index in the buffer, along with coder packed
* into higher bits.
* @param buf buffer to append to
* @param value String value to encode
* @return updated index (coder value retained)
*/
static long prepend(long indexCoder, byte[] buf, String value) {
indexCoder -= value.length();
int index = (int)indexCoder;
if (indexCoder < UTF16) {
value.getBytes(buf, (int)indexCoder, String.LATIN1);
index = StringLatin1.getChars(value, index, buf);
index -= prefix.length();
prefix.getBytes(buf, index, String.LATIN1);
return index;
} else {
value.getBytes(buf, (int)indexCoder, String.UTF16);
index = StringUTF16.getChars(value, index, buf);
index -= prefix.length();
prefix.getBytes(buf, index, String.UTF16);
return index | UTF16;
}
return indexCoder;
}

/**
Expand All @@ -323,9 +267,18 @@ static long prepend(long indexCoder, byte[] buf, String value) {
* @return updated index (coder value retained)
*/
static long prepend(long indexCoder, byte[] buf, String value, String prefix) {
indexCoder = prepend(indexCoder, buf, value);
indexCoder = prepend(indexCoder, buf, prefix);
return indexCoder;
int index = ((int)indexCoder) - value.length();
if (indexCoder < UTF16) {
value.getBytes(buf, index, String.LATIN1);
index -= prefix.length();
prefix.getBytes(buf, index, String.LATIN1);
return index;
} else {
value.getBytes(buf, index, String.UTF16);
index -= prefix.length();
prefix.getBytes(buf, index, String.UTF16);
return index | UTF16;
}
}

/**
Expand Down Expand Up @@ -368,16 +321,24 @@ static String simpleConcat(Object first, Object second) {
// newly created string required, see JLS 15.18.1
return new String(s1);
}
// start "mixing" in length and coder or arguments, order is not
// important
long indexCoder = mix(initialCoder(), s1);
indexCoder = mix(indexCoder, s2);
byte[] buf = newArray(indexCoder);
// prepend each argument in reverse order, since we prepending
// from the end of the byte array
indexCoder = prepend(indexCoder, buf, s2);
indexCoder = prepend(indexCoder, buf, s1);
return newString(buf, indexCoder);
return doConcat(s1, s2);
}

/**
* Perform a simple concatenation between two non-empty strings.
*
* @param s1 first argument
* @param s2 second argument
* @return String resulting string
*/
@ForceInline
static String doConcat(String s1, String s2) {
byte coder = (byte) (s1.coder() | s2.coder());
int newLength = (s1.length() + s2.length()) << coder;
byte[] buf = newArray(newLength);
s1.getBytes(buf, 0, coder);
s2.getBytes(buf, s1.length(), coder);
return new String(buf, coder);
}

/**
Expand Down Expand Up @@ -445,10 +406,20 @@ static byte[] newArrayWithSuffix(String suffix, long indexCoder) {
static byte[] newArray(long indexCoder) {
byte coder = (byte)(indexCoder >> 32);
int index = ((int)indexCoder) << coder;
if (index < 0) {
return newArray(index);
}

/**
* Allocates an uninitialized byte array based on the length
* @param length
* @return the newly allocated byte array
*/
@ForceInline
static byte[] newArray(int length) {
if (length < 0) {
throw new OutOfMemoryError("Overflow: String length out of range");
}
return (byte[]) UNSAFE.allocateUninitializedArray(byte.class, index);
return (byte[]) UNSAFE.allocateUninitializedArray(byte.class, length);
}

/**
Expand Down
4 changes: 0 additions & 4 deletions src/java.base/share/classes/java/lang/System.java
Original file line number Diff line number Diff line change
Expand Up @@ -2611,10 +2611,6 @@ public MethodHandle stringConcatHelper(String name, MethodType methodType) {
return StringConcatHelper.lookupStatic(name, methodType);
}

public long stringConcatHelperPrepend(long indexCoder, byte[] buf, String value) {
return StringConcatHelper.prepend(indexCoder, buf, value);
}

public long stringConcatInitialCoder() {
return StringConcatHelper.initialCoder();
}
Expand Down
Loading

0 comments on commit 62186fe

Please sign in to comment.