Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluate Architecure #231

Closed
wants to merge 22 commits into from
Closed

Evaluate Architecure #231

wants to merge 22 commits into from

Conversation

Tomschi
Copy link
Contributor

@Tomschi Tomschi commented Feb 2, 2017

Add static field for hardware architecure.

@coveralls
Copy link

coveralls commented Feb 2, 2017

Coverage Status

Coverage increased (+0.0007%) to 94.456% when pulling 13df6b0 on Tomschi:master into ab25f67 on apache:master.

@kinow
Copy link
Member

kinow commented Feb 12, 2017

I remember a discussion about it some time ago.

The issue with this approach was that os.arch tells only the JVM arch, not really OS arch.

If there is a strong use case for these properties, we would have to be careful with the javadocs. Right now the javadocs don't explicitly tell the user that it is the JVM arch, and not the OS arch.

Other approaches involve reflection or JNI, to find out the OS arch, but I think that is a bit too tricky to get it done correctly.

@PascalSchumacher
Copy link
Contributor

The discussion mentioned by @kinow is here: https://issues.apache.org/jira/browse/LANG-1145

@coveralls
Copy link

coveralls commented Feb 13, 2017

Coverage Status

Coverage decreased (-0.006%) to 94.53% when pulling a5945e7 on Tomschi:master into b715d18 on apache:master.

@Tomschi
Copy link
Contributor Author

Tomschi commented Feb 13, 2017

Rewrite javadoc's.

@kinow
Copy link
Member

kinow commented Feb 13, 2017

Thanks for updating the pull request @Tomschi.

I don't have a use case for this. I can see where it could be used, but I don't have any project where I would use it. Code is clear, javadocs have been updated :-)

So will leave it here for others to review, comment, and maybe perhaps.

@Tomschi
Copy link
Contributor Author

Tomschi commented Feb 13, 2017

I'am using it for the jacob-project. There i have to know, if it is a 32 or 64 bit architecture to load the correct dll library.

@kinow
Copy link
Member

kinow commented Feb 13, 2017

Gotcha, found this example https://github.com/Tomschi/jacob-parent/blob/ec3f1c10169c26f14ee1f61bd6622c67a73e26fc/jacob/src/main/java/com/jacob/com/LibraryLoader.java#L202

Looks like a valid use case. I'm all right with merging it, my +0. Let's now wait to see what others think about it.

Thanks!

@PascalSchumacher
Copy link
Contributor

I think this is a worthy addition.

In my experience people often do not read documentation. Maybe we should use IS_32_BIT_JVM so there can be no confusion? Or is this is too paranoid? What do you think?

@kinow
Copy link
Member

kinow commented Feb 14, 2017

Oh, good point @PascalSchumacher have no objection to it. We could probably avoid a few misunderstandings that way. Happy with that too @Tomschi ?

@Tomschi
Copy link
Contributor Author

Tomschi commented Feb 15, 2017

It's ok for me, i will change it.

@coveralls
Copy link

coveralls commented Feb 17, 2017

Coverage Status

Coverage increased (+0.001%) to 94.53% when pulling 3e335fd on Tomschi:master into 30c85ad on apache:master.

@PascalSchumacher
Copy link
Contributor

jira issue: https://issues.apache.org/jira/browse/LANG-1313

I plan to merge this tomorrow (if there are no objections).

@michael-o
Copy link
Member

michael-o commented Feb 20, 2017

What is the real pupose for this actually? The client should not care about the arch at all. The regex match is brittle. This will likely fail on ARM and it fails here on Itanium with HP-UX for os.arch IA64N which is a 32 bit VM. I would not add something like this to Commons.

@kinow
Copy link
Member

kinow commented Feb 21, 2017

@michael-o

What is the real pupose for this actually? The client should not care about the arch at all.

I think @Tomschi use case is valid, where a client could need to know the arch before loading a certain library, and we had another issue submitted LANG-1145 with similar requirement.

The regex match is brittle. This will likely fail on ARM and it fails here on Itanium with HP-UX for os.arch IA64N which is a 32 bit VM.

Note taken, perhaps before merging we can try to cover more archs, like this list:

There is another place where arch is used within Commons too:

We can possibly look at how crypto is using it, and if we could maybe use a similar approach here.

@michael-o
Copy link
Member

@kinow The cheapest way is to produce two bundles, one for 32 bit and one for 64 bit, if possible. The lopica source is useless, it is 15 years old. Commons Crypto is better. hawtjni on GitHub has decent detection code. It is work checking. But the current approach is way too simple.

@kinow
Copy link
Member

kinow commented Mar 7, 2017

Looks better now @Tomschi did you use Crypto's code as reference? cc @michael-o

@Tomschi
Copy link
Contributor Author

Tomschi commented Mar 7, 2017

Yes, the base of my code references to the commons crypto lib.

@kinow
Copy link
Member

kinow commented Mar 7, 2017

Excellent @Tomschi

I'm dropping a note to the mailing list to ask for feedback from crypto devs, as there could be some synergy.

I will play with the code at home, but one thing that I noticed is that it seems to contain tabs... minor nit pick, but could you check checkstyle and make sure the code is not introducing any warnings / errors there, please? That way it will be easier to merge the PR.

Thanks!
B

@Tomschi
Copy link
Contributor Author

Tomschi commented Mar 7, 2017

I'm sorry. I removed the tabs. Style should be ok now.


static {
map = new HashMap<>();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HashMap is not thread-safe.
Since there are public methods which can also update the map, this means the class is not thread-safe either.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. The crypto implementation doesn't allow changes to the map after it has been created. I think we can use a ConcurrentHashMap, or simply follow what was done in crypto.

@Tomschi
Copy link
Contributor Author

Tomschi commented Mar 10, 2017

There's no point in having the isXXX() methods any more.
There just need to be methods to get the Processor.
If necessary, the Processor class could have isxxx methods on it.

This methods are for me an easy and null safe way for evaluating. Further, this methods are the reason, why i have done this pull request.

private static final void addProcessor(Processor processor) throws UnsupportedOperationException {
if (!map.containsKey(processor.getName())) {
map.put(processor.getName(), processor);
private static final void addProcessor(String key, Processor processor) throws UnsupportedOperationException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the parameters were changed to (Processor processor, String key ...) there would be no need to create the List and unpack it.

@sebbASF
Copy link
Contributor

sebbASF commented Mar 10, 2017

In which case, I think they belong on the Processor class.

The user code would look like:

Processor proc = ArchUtils.getProcessor([String]);
if (proc != null) {
    if (proc.isX86() && proc.isPPC()) {
    }
} // else not supported

At present the same code is

if (ArchUtils.isSupported([String])) {
    if (ArchUtils.isX86([String]) && ArchUtils.isPPC([String]) )
    }
}

I think that looks more complicated.
Also all the isXXX methods have to be overloaded with an optional string parameter.
And the map is accessed at least 3 times.

return ProcessorArch.BIT_32.equals(processor.getProcessorArch());
} else {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code could be simplified:

Processor processor = map.get(value);
return processor != null && ProcessorArch.BIT_32.equals(processor.getProcessorArch());

Similarly for other related methods

@coveralls
Copy link

coveralls commented Mar 12, 2017

Coverage Status

Coverage decreased (-0.02%) to 94.513% when pulling 85ea6ce on Tomschi:master into d43e1d0 on apache:master.

@Tomschi
Copy link
Contributor Author

Tomschi commented Mar 15, 2017

@sebbASF I refactored the classes. Do you have any suggestions, or is it ok?

map.put(key, processor);
} else {
String msg = "Key " + key + " already exists in processor map";
throw new UnsupportedOperationException(msg);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IllegalStateException might be better here

@sebbASF
Copy link
Contributor

sebbASF commented Mar 16, 2017

I thought the idea was to move the isXXX methods to the Processor class.

You could then say

Processor processor = ArchUtils.getProcessor();
processor.is32Bit();
processor.isPPC();
etc.

@Tomschi
Copy link
Contributor Author

Tomschi commented Mar 20, 2017

I'm not sure, if we really need the isXXX methods in the Processor class, because i can directly equal the enums.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 94.589% when pulling dbdb045 on Tomschi:master into 5d6c176 on apache:master.

@coveralls
Copy link

coveralls commented Mar 20, 2017

Coverage Status

Coverage decreased (-0.02%) to 94.552% when pulling dbdb045 on Tomschi:master into 5d6c176 on apache:master.

assertNotNull(ArchUtils.getProcessor(X86));
assertNull(ArchUtils.getProcessor("NA"));
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no tests for Processor type.

@sebbASF
Copy link
Contributor

sebbASF commented Mar 20, 2017

Agreed it's not necessary to have the isXXX methods.
However it makes the user code shorter and simpler.

Currently the code is:

Processor processor = ArchUtils.getProcessor();
if (ProcessorArch.BIT_32.equals(processor.getProcessorArch())) {}
if (ProcessorType.PPC.equals(processor.getProcessorType())) {}

It would become:

Processor processor = ArchUtils.getProcessor();
if (processor.is32Bit()) {}
if (processor.isPPC()) {}

As well as being longer, in the first case one has to remember to whether to use ProcessorArch or ProcessorType

@sebbASF
Copy link
Contributor

sebbASF commented Mar 20, 2017

Also it occurs to me that ProcessorArch and ProcessorType could perhaps be subtypes of Processor (Arch and Type). They don't really have an independent existence, so do they need separate classes?

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.009%) to 94.559% when pulling a9c6f59 on Tomschi:master into 5d6c176 on apache:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.009%) to 94.559% when pulling a9c6f59 on Tomschi:master into 5d6c176 on apache:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 94.597% when pulling 29941f4 on Tomschi:master into 5d6c176 on apache:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 94.597% when pulling 29941f4 on Tomschi:master into 5d6c176 on apache:master.

@PascalSchumacher
Copy link
Contributor

@sebbASF What do you think about the latest changes? Is this pull request ready for merging?

Thanks, Pascal

@sebbASF
Copy link
Contributor

sebbASF commented Mar 26, 2017

looks good

@PascalSchumacher
Copy link
Contributor

Merged. Thanks!

@asfgit asfgit closed this in 90f0a68 Mar 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants