Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
denzelcurrypower
Jan 28, 2011

Fergus Mac Roich posted:

I happen to have a brand new OnePlus 3. I just plugged it in with "USB Debugging" enabled and it seemed to install the drivers just fine. I happen to be doing a fresh install of Android Studio as we speak so I'll update on what happens there with a default application.

fake-edit: This is connected to a Windows 10 PC with the latest large update that came out recently.

FWIW, I have an i5-3570 and the emulator hasn't ever been unusably slow in the past, though it is slow.

Real-edit: Okay, I got Android Studio up and running. It prompts you on the OnePlus 3 itself before you're able to run the app on your device; is your device unlocked while you're doing all this? My best guess other than that would be some kind of old driver version conflict, something like that.

Appreciate the help, I eventually got it working. I had to manually point the device to the android USB driver within a whole bunch of sub menus on device manager.

Sadly the emulator is much much better on Intel processors due to the HAXM technology, it's just about useless on my AMD desktop.

Sorry for the detail due to my tech issues, I appreciate the help everyone.

Adbot
ADBOT LOVES YOU

Jo
Jan 24, 2005

:allears:
Soiled Meat
Not sure if this belongs in the 3D tread. What are my options for debugging and benchmarking OpenCL in Java? (I'm using JoCL.)

I have an OpenCL application I'm making with JoCL and I'm having a hard time figuring out why the hotspots are what they are. The Java Mission Control application says that my program is spending most of its time in java.lang.integer.equals. That seems completely wrong. I've not been able to use any of nVidia's tools to debug the OpenCL code (since it seems to expect a C++ program). I'm out of ideas for finding out the source of the problem. The GPU is _way_ faster for most tasks, but I think the copying to and from system memory is hurting. I just wouldn't have expected it to hurt _that much_. What are my options for debugging and benchmarking OpenCL in Java?

My source code is here: https://github.com/josephcatrambone/aij The GPUGraph is the subject of the inquiry.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Jo posted:

I have an OpenCL application I'm making with JoCL and I'm having a hard time figuring out why the hotspots are what they are. The Java Mission Control application says that my program is spending most of its time in java.lang.integer.equals. That seems completely wrong.

The screenshot says that almost all of that time being spent in equals because ArrayList.indexOf is calling equals a lot. That seems completely plausible if indexOf is being called a lot on big lists - every call to indexOf effectively iterates over the entire list to try and find the right element.

If you expand the list of things that call indexOf (and keep expanding until you see something you recognize), does that clarify what's being slow?

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.
Try changing shapes from List to HashMap and see how that effects the performance. You call getShape() a lot in GPUGraph.java and that's O(N) each time.

Sorry, I can't answer your real question, haven't had to debug C++ calls from Java and I'm not sure how to go about that either.

You won't be able to attach to the java program, so you'll probably have to attach to the shared library. You may even have to get a debug build of the library and compile your java program against the debug library before it'll work.

Jo
Jan 24, 2005

:allears:
Soiled Meat

Jabor posted:

The screenshot says that almost all of that time being spent in equals because ArrayList.indexOf is calling equals a lot. That seems completely plausible if indexOf is being called a lot on big lists - every call to indexOf effectively iterates over the entire list to try and find the right element.

If you expand the list of things that call indexOf (and keep expanding until you see something you recognize), does that clarify what's being slow?

Zaphod42 posted:

Try changing shapes from List to HashMap and see how that effects the performance. You call getShape() a lot in GPUGraph.java and that's O(N) each time.

Sorry, I can't answer your real question, haven't had to debug C++ calls from Java and I'm not sure how to go about that either.

You won't be able to attach to the java program, so you'll probably have to attach to the shared library. You may even have to get a debug build of the library and compile your java program against the debug library before it'll work.

Isn't ArrayList O(1)? I get that a Linked List would be O(n), but an array list should be as fast as a direct memory seek.

In either case, it's still hard for me to believe that the program is spending 50% of its time doing isEqual when the graph has only twelve nodes. Even with a non-memoized implementation that shouldn't be more than 144 calls to the method compared to 1000*1000 multiplications PER LOOP.

Fake Edit: The doc says an array list access should be O(1). It's just doing an array lookup.

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

Jo posted:

Isn't ArrayList O(1)? I get that a Linked List would be O(n), but an array list should be as fast as a direct memory seek.

In either case, it's still hard for me to believe that the program is spending 50% of its time doing isEqual when the graph has only twelve nodes. Even with a non-memoized implementation that shouldn't be more than 144 calls to the method compared to 1000*1000 multiplications PER LOOP.

Fake Edit: The doc says an array list access should be O(1). It's just doing an array lookup.

ArrayList .get() is O(1), but ArrayList .contains() or .indexOf() is O(N) because you don't know which array index the item is kept in. It could be anywhere.

If you sort the array you get better than O(N) time but its still sub O(1) by a longshot, and then you have to keep the list sorted.

Only HashMap gets you O(1) lookup because the object's hashcode gives you the array index it would be located in. There's no way to know if an ArrayList contains something unless you scan the entire list.

Zorro KingOfEngland
May 7, 2008

ArrayList's .get() is O(1), but .indexOf() is O(n) because you have to get each object and test its equality until you find the one you're looking for.

If you look at the source code for ArrayList's indexOf you'll see that it just loops through elements until it finds one that equals: Here

A HashMap like Zaphod42 was suggesting would probably be a better fit for your problem.

efb.

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.
If you're willing to come up with a scheme where object A is only kept at index 0 and object B is always index 1 and so on, then you get O(1) from an ArrayList

But then you're just turning it into a HashMap that is backed by an ArrayList.

See the difference?

Trapick
Apr 17, 2006

Is there a standard recommendation for learning Spring (specifically Spring Boot)? Course or book or tutorial series, whatever. I'm no Java expert, if that helps.

Jo
Jan 24, 2005

:allears:
Soiled Meat

Zorro KingOfEngland posted:

ArrayList's .get() is O(1), but .indexOf() is O(n) because you have to get each object and test its equality until you find the one you're looking for.

If you look at the source code for ArrayList's indexOf you'll see that it just loops through elements until it finds one that equals: Here

A HashMap like Zaphod42 was suggesting would probably be a better fit for your problem.

efb.

Aha! Well I'll have to trace down where index of is being called. If get() is actually calling it, I'd call that a bug in the docs because it means the runtime isn't as advertised. I'll just switch to a standard array and resize it as I add elements to the graph. No need to use a hashmap.

Edit: OpenJDK's source indicates it's constant time. I wonder where that indexOf is getting called. Maybe I'm going down the rabbit hole with this one. Even with a fuckload of linear seeks, there's no way that finding an item in a list of length 12 takes 50% of a five-minute run. I think it's just the case that Java mission control can't effectively profile stuff that's native. It's probably not counting the two-minute matrix multiply or 30-second opencl compile. Treats it as blocked io?

Jo fucked around with this message at 00:43 on Oct 5, 2016

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Jo posted:

Aha! Well I'll have to trace down where index of is being called. If get() is actually calling it, I'd call that a bug in the docs because it means the runtime isn't as advertised. I'll just switch to a standard array and resize it as I add elements to the graph. No need to use a hashmap.

Edit: OpenJDK's source indicates it's constant time. I wonder where that indexOf is getting called. Maybe I'm going down the rabbit hole with this one. Even with a fuckload of linear seeks, there's no way that finding an item in a list of length 12 takes 50% of a five-minute run. I think it's just the case that Java mission control can't effectively profile stuff that's native. It's probably not counting the two-minute matrix multiply or 30-second opencl compile. Treats it as blocked io?

You don't need to wonder! You can literally just expand the nodes in that stack trace view to find out where it's being called!

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

Zaphod42 posted:

Try changing shapes from List to HashMap and see how that effects the performance. You call getShape() a lot in GPUGraph.java and that's O(N) each time.

Jo posted:

Aha! Well I'll have to trace down where index of is being called. If get() is actually calling it, I'd call that a bug in the docs because it means the runtime isn't as advertised. I'll just switch to a standard array and resize it as I add elements to the graph. No need to use a hashmap.

Edit: OpenJDK's source indicates it's constant time. I wonder where that indexOf is getting called.

I already told you. IndexOf is called in getShape().

code:
if(shapes.contains(node)) {
	return shapes.get(node);
}
That's O(N) each time, and you call getShape() multiple times. How big is the shapes arraylist and how many times are you calling it? HashMap would make that O(1).

I guess that's not indexOf() in particular, although I wouldn't be surprised if contains() just returns indexof(o) == -1.

For that matter, looking at your code, is shapes.contains(node) even what you want there?

You put Dimension objects into the Shapes ArrayList. Contains(int) will always return null, wont it? Seems like you're trying to do contains(index) but that's not what the contains() method does. Contains is for passing an object that would be in the array, not an index.

code:
try{
  Shape s = shapes.get(node);
  if(s != null) {
	return s;
  }
}
catch(IndexOutOfBoundsException e)
{
//nothing found
}
//do other stuff

Zaphod42 fucked around with this message at 01:37 on Oct 5, 2016

CPColin
Sep 9, 2003

Big ol' smile.
The try-catch will probably be a bunch slower than a range check would be, if you expect to be out of range a lot.

For the other issue, if nulls are the billion-dollar mistake, List.indexOf() and Map.get() taking Object instead of their parameterized type has got to be worth a couple hundred thousand.

Jo
Jan 24, 2005

:allears:
Soiled Meat

Zaphod42 posted:

I already told you. IndexOf is called in getShape().

code:
if(shapes.contains(node)) {
	return shapes.get(node);
}
That's O(N) each time, and you call getShape() multiple times. How big is the shapes arraylist and how many times are you calling it? HashMap would make that O(1).

I guess that's not indexOf() in particular, although I wouldn't be surprised if contains() just returns indexof(o) == -1.

For that matter, looking at your code, is shapes.contains(node) even what you want there?

You put Dimension objects into the Shapes ArrayList. Contains(int) will always return null, wont it? Seems like you're trying to do contains(index) but that's not what the contains() method does. Contains is for passing an object that would be in the array, not an index.

code:
try{
  Shape s = shapes.get(node);
  if(s != null) {
	return s;
  }
}
catch(IndexOutOfBoundsException e)
{
//nothing found
}
//do other stuff

:downs: gently caress, I need to work on my reading comprehension. You're absolutely right. I don't actually need the check. The base-case is handled by the inputs in the case anyway.

That changes the profile a good bit.



Still think I need to profile the OpenCL component separately, since the performance on the GPU instance is markedly better for most tasks but incurs a high one-time overhead starting up.

Thanks everyone for the help -- removing that O(n) check shaved a nice 10% off the CPU benchmarks I had. :neckbeard:

Jo fucked around with this message at 08:05 on Oct 5, 2016

Squashy Nipples
Aug 18, 2007

Hey guys, after 9 months off, I'm back to teaching myself Java (slowly).

Look what I just tried:
code:
int[i] ++;
It' doesn't work, and neither did this:

code:
int[i] = int[i] + 1;
I have a cup of dice, and I want to return a 6-member array of integers, each containing the number of occurrences of each side.
(6-member array because they are six-sided dice, and the cup can contain any number of dice)

code:
    public int[] resultCount(){
        
        int[] temp = new int[6];
        
        for ( int i = 0 ; i < 6 ; i ++){
            for (Die die : cup ){
                if (die.getSide() == i) {
                    int[i] = int[i] + 1;
                }
            }
        }
        return temp;
    }
Advice, please.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Squashy Nipples posted:

Hey guys, after 9 months off, I'm back to teaching myself Java (slowly).

Look what I just tried:
code:
int[i] ++;
It' doesn't work, and neither did this:

code:
int[i] = int[i] + 1;
I have a cup of dice, and I want to return a 6-member array of integers, each containing the number of occurrences of each side.
(6-member array because they are six-sided dice, and the cup can contain any number of dice)

code:
    public int[] resultCount(){
        
        int[] temp = new int[6];
        
        for ( int i = 0 ; i < 6 ; i ++){
            for (Die die : cup ){
                if (die.getSide() == i) {
                    int[i] = int[i] + 1;
                }
            }
        }
        return temp;
    }
Advice, please.

Your variable is called temp, so temp[i]++;

I'm curious what error you're getting from the compiler.

smackfu
Jun 7, 2004

When do you change the value of temp?

And don't call variables "temp".

Squashy Nipples
Aug 18, 2007

LOL, that was stupid. Next time reread before reposting.

Thanks guys.

Squashy Nipples
Aug 18, 2007

smackfu posted:

When do you change the value of temp?

And don't call variables "temp".

Well, I'm used to have the function name available as a temp variable, so I didn't know what else to call something that only exists within the scope of the Method.

But yeah, definitely not the best idea.

Squashy Nipples
Aug 18, 2007

carry on then posted:

I'm curious what error you're getting from the compiler.




OK, here is the code that does what I want:
code:
    public int[] resultCount(){
        
        int[] results = new int[6];
        
        for ( int i = 0 ; i < 6 ; i ++){
            for (Die die : cup ){
                if (die.getSide() == (i + 1)) {
                    results[i] ++;
                }
            }
        }
        return results;
    }
Test results: (5 dice in the cup)
code:
Die Number (0): 4
Die Number (1): 5
Die Number (2): 2
Die Number (3): 4
Die Number (4): 3
ToString value: 45243
Count of 1's: 0
Count of 2's: 1
Count of 3's: 1
Count of 4's: 2
Count of 5's: 1
Count of 6's: 0
One last question: when you initialize an array like I did ( int[] results = new int[6]; ), do I get an array of zeros, or an array of NULLs?

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

Squashy Nipples posted:

One last question: when you initialize an array like I did ( int[] results = new int[6]; ), do I get an array of zeros, or an array of NULLs?

int is a primitive data type, not an Object, in Java. So ints cannot be null. There's an Object which wraps the int plain data type called Integer, which has methods and is an object so it can be null.

ints default to 0 as a result, while Objects default to null.

so int[] myArray = int[10]; creates 10 zeros.

Integer[] myArray = Integer[10]; creates 10 null references.

You can also set the values as you initialize, like int[] myArray = {0, 1, 2}; which will cause them to be initialized to what you set, instead of 0.

Note that the difference between primitives and Objects in java can be somewhat confusing because of a handy syntactic feature called autoboxing.

If you say

Integer x = new Integer(5);
int[] myArray = new int[10];

you can legally do

myArray[2] = x;

Even though Integer is an Object. Java will automatically "unbox" the plain data int from within the Integer, and place that in the array.

You can also do the opposite, called "boxing"

int x = 5;
Integer[] myArray = new Integer[10];

myArray[5] = x;

Hope that clears it all up! Primitives are a special case of the language and are pretty much the only things in Java that aren't Objects, as they are necessary fundamentals. Everything else is made of Objects which either contain Primitives or other Objects.

Squashy Nipples
Aug 18, 2007

A thorough explanation, thank you.

I recall reading discussions of boxing/unboxing, but some aspects of it take a while to sink in.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)


Yeah that's not pretty.

denzelcurrypower
Jan 28, 2011
Can anyone recommend a guide for a beginner to learn the Spring framework?

My teacher has been showing us how to build very basic Java Web applications using NetBeans and now we have an assignment to make a Spring MVC application. I'm really getting overwhelmed. I tried using the NetBeans template for Spring MVC but it seems they use deprecated classes which their guide acknowledges but provides no recourse.

I tried looking at some examples from the book Spring in Action 4th edition but it seems like they use a completely different build structure which I can't even open in NetBeans, and starting a NetBeans Spring project and then following the textbook ends up with all kinds of import errors.

Overall I'm very confused as it seems to be totally different than the bare bones servlets we have made in class so far. I haven't even got a hello world example to run properly yet...

Paul MaudDib
May 3, 2006

TEAM NVIDIA:
FORUM POLICE

Ornithology posted:

Can anyone recommend a guide for a beginner to learn the Spring framework?

My teacher has been showing us how to build very basic Java Web applications using NetBeans and now we have an assignment to make a Spring MVC application. I'm really getting overwhelmed. I tried using the NetBeans template for Spring MVC but it seems they use deprecated classes which their guide acknowledges but provides no recourse.

I tried looking at some examples from the book Spring in Action 4th edition but it seems like they use a completely different build structure which I can't even open in NetBeans, and starting a NetBeans Spring project and then following the textbook ends up with all kinds of import errors.

Overall I'm very confused as it seems to be totally different than the bare bones servlets we have made in class so far. I haven't even got a hello world example to run properly yet...

https://github.com/kolorobot/spring-mvc-quickstart-archetype

There's instructions there, first you will need to install the archetype and then create an instance of it.

I'm wondering if "different build structure" means Maven and if so you're going to have to handle it sooner or later. It's essentially an IDE-agnostic build system with dependency management and from your import errors it sounds like you tried shoehorning the project code into a Netbeans project and so it's not doing any of the dependency management that it's supposed to. There should be a "import Maven POM project" option or something similar that you use.

Also, IntelliJ is by far the best IDE in the Java world and you get a free copy as a student so you should do that too.

Paul MaudDib fucked around with this message at 23:35 on Oct 7, 2016

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.
Getting the right versions and dependencies can be a big pain. Spring is a pretty big heavyweight library, and while its very good and popular, I've always preferred things that are more lightweight and easier to just use the bit you need.

Using a bunch of existing code is nice because it gives you all this powerful stuff, but just getting the configuration right can take a lot of fiddling and is not at all fun.

The solution as MuadDib said is probably to use Maven, which will require you to set it up and configure it, but then should automatically guarantee your spring application will build and launch properly.

Trapick
Apr 17, 2006

Paul MaudDib posted:

Also, IntelliJ is by far the best IDE in the Java world and you get a free copy as a student so you should do that too.
For beginners (but not student, so would cost dollars), is the Ultimate edition significantly better than the Community edition?

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Trapick posted:

For beginners (but not student, so would cost dollars), is the Ultimate edition significantly better than the Community edition?

I used community all through college and never needed a feature that was ultimate-only.

Sedro
Dec 31, 2008

Trapick posted:

For beginners (but not student, so would cost dollars), is the Ultimate edition significantly better than the Community edition?

The Ultimate edition mostly adds web-dev related stuff, like JavaScript syntax highlighting (you can still use Community edition as a dumb text editor).

Literal Hamster
Mar 11, 2012

YOSPOS
I have a class named ImageData with subclasses SuccessData and FailureData.

Can I produce two separate collections, one containing only the SuccessData objects, and the other containing only the FailureData objects, using Java 8 Streams in a single fluent expression?

more like dICK
Feb 15, 2010

This is inevitable.
Yes kind of.

code:
        List<ImageData> data = new ArrayList<>();

        Collections.addAll(data, new FailureData(), new FailureData(), new FailureData());
        Collections.addAll(data, new SuccessData(), new SuccessData(), new SuccessData(), new SuccessData());
        
        Map<Boolean, List<ImageData>> partitionedData = data.stream().collect(Collectors.partitioningBy(id -> id instanceof SuccessData));

        System.out.println(partitionedData.get(Boolean.TRUE).size()); // SuccessData instances
        System.out.println(partitionedData.get(Boolean.FALSE).size()); // FailureData instances
Obviously failing the predicate doesn't 100% guarantee that the object is an instance of FailureData, but this is close enough for most uses.

denzelcurrypower
Jan 28, 2011
Thanks for the suggestions regarding the Spring framework, guys. I've got Hello World working now at least but I've run into an issue with iterating over a collection in a jsp file. Any helps would be highly appreciated.. I'm sure it's a simple fix that I'm missing.

edit: Fixed - code removed, I was missing taglib reference on the jsp page

denzelcurrypower fucked around with this message at 07:03 on Oct 8, 2016

ToxicSlurpee
Nov 5, 2003

-=SEND HELP=-


Pillbug

Ornithology posted:

Thanks for the suggestions regarding the Spring framework, guys. I've got Hello World working now at least but I've run into an issue with iterating over a collection in a jsp file. Any helps would be highly appreciated.. I'm sure it's a simple fix that I'm missing.

edit: Fixed - code removed, I was missing taglib reference on the jsp page

Jsp files are...kind of poo poo. Look into thymeleaf for you templates.

CPColin
Sep 9, 2003

Big ol' smile.
I spent a couple hours a few days ago trying to figure out why, no matter what I did, turning on Thymeleaf's caching didn't seem to do anything. It finally worked when I used reflection to get the field I needed, set it to be accessible, and set it myself.

Then I discovered that turning off JRebel made it work fine. Thanks, JRebel.

denzelcurrypower
Jan 28, 2011

ToxicSlurpee posted:

Jsp files are...kind of poo poo. Look into thymeleaf for you templates.

Thanks for the suggestion. The curriculum in my school program seems pretty out of date so it's always good to know the better options that I should be learning!

Tern
Oct 18, 2012

ToxicSlurpee posted:

Jsp files are...kind of poo poo. Look into thymeleaf for you templates.

Thymeleaf is awesome, however its documentation does leave something to be desired. Or maybe that's just because my brain has been poisoned by too many years of JSTL nonsense.

Carbon dioxide
Oct 9, 2012

At work I use jsp's a lot, simply because that was the only thing our cms supported back when they started working with it. Some new stuff uses freemarker, and for automated e-mails we use velocity templates.

I have to say I find it kinda hard to see how one is better than the other, they all seem very similar to me.

ToxicSlurpee
Nov 5, 2003

-=SEND HELP=-


Pillbug

Ornithology posted:

Thanks for the suggestion. The curriculum in my school program seems pretty out of date so it's always good to know the better options that I should be learning!

School programs typically are, sadly. Don't sweat it too much; thymeleaf will eventually be old garbage nobody uses some day too. Jsp stuff is just old, showing its age, and has security issues. Xss problems are the big one. It's neat and not totally awful (it still gets a good amount of use) there are just better options.

Data Graham
Dec 28, 2009

📈📊🍪😋



Such as not using java?

I actually don't mean that to sound snarky. I'm really wondering: what are the benefits of using Java for web dev, when there are plenty of other stacks available that don't require you to muck around with IDEs or roll your own DAOs? Is the performance benefit that significant? Or is it all about scale, for maintainability of large codebases?

Adbot
ADBOT LOVES YOU

more like dICK
Feb 15, 2010

This is inevitable.
Performance, library support, maintainability, deployment simplicity are all reasons I use java even when I'm not being paid to.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply