Re: [PATCH] java.util.Collections enhancement

2017-09-11 Thread Tagir Valeev
Also note that this changes visible behavior. E.g. somebody might
synchronize on the array object returned by toArray call, so this
change might cause unwanted lock sharing.

Once I suggested similar improvement: to return EMPTY_LIST from
Arrays.asList() when supplied array has zero length. It was declined
with the same reason [1]

With best regards,
Tagir Valeev.

[1] 
http://mail.openjdk.java.net/pipermail/core-libs-dev/2015-September/035197.html

On Tue, Sep 12, 2017 at 4:27 AM, David Holmes  wrote:
> Moving to core-libs-dev ...
>
> On 12/09/2017 5:40 AM, Сергей Цыпанов wrote:
>>
>> Hi,
>>
>> looking into the code of java.util.Collections I've found out that
>> EmptyList#toArray() and EmptySet#toArray() both instantiate new instance of
>> Object[] at each call. As far as Java array is immutable it's possible to
>> cache empty Object array and return this cached instance.
>
>
> There is a slight issue with the specification of toArray here:
>
> "The returned array will be "safe" in that no references to it are
> maintained by this list. (In other words, this method must allocate a new
> array even if this list is backed by an array). "
>
> Of course for a zero-sized array it is perfectly safe to return a cached
> array, but the spec currently requires that a new array be returned.
>
> Cheers,
> David
> -
>
>> Patch.txt is attached to the body of this mail.
>>
>> Thanks,
>> - Sergei Tsypanov
>>
>> patch.txt
>>
>> diff --git a/src/java.base/share/classes/java/util/Collections.java
>> b/src/java.base/share/classes/java/util/Collections.java
>> --- a/src/java.base/share/classes/java/util/Collections.java
>> +++ b/src/java.base/share/classes/java/util/Collections.java
>> @@ -108,6 +108,11 @@
>>  private static final int INDEXOFSUBLIST_THRESHOLD =   35;
>>   /**
>> + * Cached empty array
>> + */
>> +private static final Object[] EMPTY_ARRAY = {};
>> +
>> +/**
>>   * Sorts the specified list into ascending order, according to the
>>   * {@linkplain Comparable natural ordering} of its elements.
>>   * All elements in the list must implement the {@link Comparable}
>> @@ -4329,7 +4334,7 @@
>>  public boolean contains(Object obj) {return false;}
>>  public boolean containsAll(Collection c) { return c.isEmpty();
>> }
>>  -public Object[] toArray() { return new Object[0]; }
>> +public Object[] toArray() { return EMPTY_ARRAY; }
>>   public  T[] toArray(T[] a) {
>>  if (a.length > 0)
>> @@ -4458,7 +4463,7 @@
>>  public boolean contains(Object obj) {return false;}
>>  public boolean containsAll(Collection c) { return c.isEmpty();
>> }
>>  -public Object[] toArray() { return new Object[0]; }
>> +public Object[] toArray() { return EMPTY_ARRAY; }
>>   public  T[] toArray(T[] a) {
>>  if (a.length > 0)
>
>


Re: [PATCH] java.util.Collections enhancement

2017-09-11 Thread David Holmes

Moving to core-libs-dev ...

On 12/09/2017 5:40 AM, Сергей Цыпанов wrote:

Hi,

looking into the code of java.util.Collections I've found out that 
EmptyList#toArray() and EmptySet#toArray() both instantiate new instance of 
Object[] at each call. As far as Java array is immutable it's possible to cache 
empty Object array and return this cached instance.


There is a slight issue with the specification of toArray here:

"The returned array will be "safe" in that no references to it are 
maintained by this list. (In other words, this method must allocate a 
new array even if this list is backed by an array). "


Of course for a zero-sized array it is perfectly safe to return a cached 
array, but the spec currently requires that a new array be returned.


Cheers,
David
-


Patch.txt is attached to the body of this mail.

Thanks,
- Sergei Tsypanov

patch.txt

diff --git a/src/java.base/share/classes/java/util/Collections.java 
b/src/java.base/share/classes/java/util/Collections.java
--- a/src/java.base/share/classes/java/util/Collections.java
+++ b/src/java.base/share/classes/java/util/Collections.java
@@ -108,6 +108,11 @@
 private static final int INDEXOFSUBLIST_THRESHOLD =   35;
 
 /**

+ * Cached empty array
+ */
+private static final Object[] EMPTY_ARRAY = {};
+
+/**
  * Sorts the specified list into ascending order, according to the
  * {@linkplain Comparable natural ordering} of its elements.
  * All elements in the list must implement the {@link Comparable}
@@ -4329,7 +4334,7 @@
 public boolean contains(Object obj) {return false;}
 public boolean containsAll(Collection c) { return c.isEmpty(); }
 
-public Object[] toArray() { return new Object[0]; }

+public Object[] toArray() { return EMPTY_ARRAY; }
 
 public  T[] toArray(T[] a) {

 if (a.length > 0)
@@ -4458,7 +4463,7 @@
 public boolean contains(Object obj) {return false;}
 public boolean containsAll(Collection c) { return c.isEmpty(); }
 
-public Object[] toArray() { return new Object[0]; }

+public Object[] toArray() { return EMPTY_ARRAY; }
 
 public  T[] toArray(T[] a) {

 if (a.length > 0)




Re: Set the effective user ID of the Java process.

2017-09-11 Thread Jonathan Yu
On Mon, Sep 11, 2017 at 5:31 AM, Dmitrii Kashin  wrote:

>
> I'd like to add to the conversation that this thread was started because
> of the argue here[1] (russian).
>
> The main point of the argue was dropping privileges from root to some
> user after the program performed all the needed actions (f.e. when it
> started listening port < 1024).
>

root isn't needed for binding service ports anymore, you can use setcap:
https://stackoverflow.com/a/414258

>
> We've found an example in commons-daemon code[2] how to drop privileges
> in MS Windows systems. It seems a new Access Token is created for some
> unprivileged user, and then spawns a new process with this token.
>
> I suppose it makes some sense to say about it here: it would be very
> useful to have a possibility to drop privileges to some user. Please
> consider it as a user request.
>
> [1] https://www.opennet.ru/opennews/art.shtml?num=47170#29
> [2] https://github.com/apache/commons-daemon/blob/
> 6702852984689bc6507690113949b478dba157ef/src/native/windows/
> src/rprocess.c#L481
>
> bruno ais  writes:
>
> > Any idea how it can be done on Windows?
> > Or better yet; is there a cross-platform thing or equivalence of that
> > feature?
> > If not, then that can easily be the reason.
> >
> > On Mon, Sep 11, 2017 at 9:29 AM, DoWhile ForEach <
> dowhilefore...@gmail.com>
> > wrote:
> >
> >> Hello.
> >>
> >> Please explain someone why the Java API has not yet implemented a method
> >> that allows you to set the effective user ID of the Java process.
> >>
> >> To accomplish this simple task, you have to make some workarounds.
> >> A striking example of such workarounds is jsvc tool from the Apache
> >> commons-daemon project for Tomcat server:
> >> https://github.com/apache/commons-daemon/blob/6702852984689b
> >> c6507690113949b478dba157ef/src/native/unix/native/jsvc-unix.c#L163
> >>
>



-- 
Cheers,

Jonathan


Re: RFR 8145635 : Add TCP_QUICKACK socket option

2017-09-11 Thread vyom tewari

Hi All,

As jdk.net API already moved out of java.base, Please review the below 
code change for jdk10.


Bug: https://bugs.openjdk.java.net/browse/JDK-8145635

Webrev: http://cr.openjdk.java.net/~vtewari/8145635/webrev0.1/index.html

Thanks,

Vyom


On Wednesday 24 February 2016 03:16 PM, Alan Bateman wrote:


On 24/02/2016 09:16, vyom wrote:

Hi All,

Please review my code changes for the below issue.

Bug: JDK-8145635 : Add TCP_QUICKACK socket option

Webrev: http://cr.openjdk.java.net/~vtewari/8145635/webrev0.0/index.html

Currently TCP_QUICKACK is only supported on Linux( since Linux 2.4.4) 
so i implemented is as "ExtendedSocketOption".


Is there any urgency on this one? I'm just wondering if we should try 
to the jdk.net API moved out of java.base before we add more socket 
options. This is currently tracked as JDK-8044773 and important to get 
into JDK 9.


-Alan




Re: Set the effective user ID of the Java process.

2017-09-11 Thread Andrew Haley
On 11/09/17 09:29, DoWhile ForEach wrote:
> 
> Please explain someone why the Java API has not yet implemented a method
> that allows you to set the effective user ID of the Java process.

Because it's tricky to do in Java, but trivial to do in C and then use
the invocation API?

-- 
Andrew Haley
Java Platform Lead Engineer
Red Hat UK Ltd. 
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671


Re: Set the effective user ID of the Java process.

2017-09-11 Thread dalibor topic

Sounds like https://bugs.openjdk.java.net/browse/JDK-5032600 .

cheers,
dalibor topic

On 11.09.2017 14:31, Dmitrii Kashin wrote:


I'd like to add to the conversation that this thread was started because
of the argue here[1] (russian).

The main point of the argue was dropping privileges from root to some
user after the program performed all the needed actions (f.e. when it
started listening port < 1024).

We've found an example in commons-daemon code[2] how to drop privileges
in MS Windows systems. It seems a new Access Token is created for some
unprivileged user, and then spawns a new process with this token.

I suppose it makes some sense to say about it here: it would be very
useful to have a possibility to drop privileges to some user. Please
consider it as a user request.

[1] https://www.opennet.ru/opennews/art.shtml?num=47170#29
[2] 
https://github.com/apache/commons-daemon/blob/6702852984689bc6507690113949b478dba157ef/src/native/windows/src/rprocess.c#L481

bruno ais  writes:


Any idea how it can be done on Windows?
Or better yet; is there a cross-platform thing or equivalence of that
feature?
If not, then that can easily be the reason.

On Mon, Sep 11, 2017 at 9:29 AM, DoWhile ForEach 
wrote:


Hello.

Please explain someone why the Java API has not yet implemented a method
that allows you to set the effective user ID of the Java process.

To accomplish this simple task, you have to make some workarounds.
A striking example of such workarounds is jsvc tool from the Apache
commons-daemon project for Tomcat server:
https://github.com/apache/commons-daemon/blob/6702852984689b
c6507690113949b478dba157ef/src/native/unix/native/jsvc-unix.c#L163



--
 Dalibor Topic | Principal Product Manager
Phone: +494089091214  | Mobile: +491737185961


ORACLE Deutschland B.V. & Co. KG | Kühnehöfe 5 | 22761 Hamburg

ORACLE Deutschland B.V. & Co. KG
Hauptverwaltung: Riesstr. 25, D-80992 München
Registergericht: Amtsgericht München, HRA 95603

Komplementärin: ORACLE Deutschland Verwaltung B.V.
Hertogswetering 163/167, 3543 AS Utrecht, Niederlande
Handelsregister der Handelskammer Midden-Niederlande, Nr. 30143697
Geschäftsführer: Alexander van der Ven, Jan Schultheiss, Val Maher

 Oracle is committed to developing
practices and products that help protect the environment


Re: Set the effective user ID of the Java process.

2017-09-11 Thread Dmitrii Kashin

I'd like to add to the conversation that this thread was started because
of the argue here[1] (russian).

The main point of the argue was dropping privileges from root to some
user after the program performed all the needed actions (f.e. when it
started listening port < 1024).

We've found an example in commons-daemon code[2] how to drop privileges
in MS Windows systems. It seems a new Access Token is created for some
unprivileged user, and then spawns a new process with this token.

I suppose it makes some sense to say about it here: it would be very
useful to have a possibility to drop privileges to some user. Please
consider it as a user request.

[1] https://www.opennet.ru/opennews/art.shtml?num=47170#29
[2] 
https://github.com/apache/commons-daemon/blob/6702852984689bc6507690113949b478dba157ef/src/native/windows/src/rprocess.c#L481

bruno ais  writes:

> Any idea how it can be done on Windows?
> Or better yet; is there a cross-platform thing or equivalence of that
> feature?
> If not, then that can easily be the reason.
>
> On Mon, Sep 11, 2017 at 9:29 AM, DoWhile ForEach 
> wrote:
>
>> Hello.
>>
>> Please explain someone why the Java API has not yet implemented a method
>> that allows you to set the effective user ID of the Java process.
>>
>> To accomplish this simple task, you have to make some workarounds.
>> A striking example of such workarounds is jsvc tool from the Apache
>> commons-daemon project for Tomcat server:
>> https://github.com/apache/commons-daemon/blob/6702852984689b
>> c6507690113949b478dba157ef/src/native/unix/native/jsvc-unix.c#L163
>>


Re: Set the effective user ID of the Java process.

2017-09-11 Thread bruno ais
Any idea how it can be done on Windows?
Or better yet; is there a cross-platform thing or equivalence of that
feature?
If not, then that can easily be the reason.

On Mon, Sep 11, 2017 at 9:29 AM, DoWhile ForEach 
wrote:

> Hello.
>
> Please explain someone why the Java API has not yet implemented a method
> that allows you to set the effective user ID of the Java process.
>
> To accomplish this simple task, you have to make some workarounds.
> A striking example of such workarounds is jsvc tool from the Apache
> commons-daemon project for Tomcat server:
> https://github.com/apache/commons-daemon/blob/6702852984689b
> c6507690113949b478dba157ef/src/native/unix/native/jsvc-unix.c#L163
>


Set the effective user ID of the Java process.

2017-09-11 Thread DoWhile ForEach
Hello.

Please explain someone why the Java API has not yet implemented a method
that allows you to set the effective user ID of the Java process.

To accomplish this simple task, you have to make some workarounds.
A striking example of such workarounds is jsvc tool from the Apache
commons-daemon project for Tomcat server:
https://github.com/apache/commons-daemon/blob/6702852984689bc6507690113949b478dba157ef/src/native/unix/native/jsvc-unix.c#L163