The next time it happens, I recommend that with a concerned/worried look on your face, you say in a slightly-lowered tone—like you don't want anyone to overhear—"Hey man, I'm worried that you could get in trouble for saying jokes like that. I'd hate to see some kind of consequence if someone were to overhear you making that kind of joke."
You can reaffirm the relationship as well if desired, "I like working with you and don't want anything to happen that would prevent that."
Notice that the focus of your concern is on him. There are very particular reasons for this exact style:
It locates the source of the disapproval onto a vague other person, distancing yourself from the issue. This is intentional because it reduces the challenge to the ego of the person you're speaking with. It additionally positions you as on his side instead of as being the one who is upset. This works even if the person intellectually understands that you don't like his behavior—in my experience, this kind of third-party risk seems to slot into the human psyche with positive results.
It is a safe way to raise the issue in a way that is non-threatening to the jokester, all the while still subtly communicating that there is, in fact, risk to him.
It gets the job done of communicating with the person directly, but with less at stake personally about how it's offensive to you. It isn't fair to go straight to the jokester's manager, but confrontation is hard. This is a way to be direct about the issue but feels less confrontational.
It doesn't address the person's motives, intentions, or morality, which in fact you don't know. It only addresses behavior. For all you know, he just came from a job where this kind of joke was common or even expected. By keeping it external and behavior/consequence focused, you aren't creating offense where it isn't needed, which is a risk with answers that imply "you bad person who did an evil thing". You can go down that route if you want, if once the objectionability of the behavior is communicated he does it gratuitously to offend.
Feedback is most effective when done in the moment. Later feedback that past behavior was not appropriate is far less effective. People have trouble connecting past actions to present feedback. Giving the feedback immediately will have the greatest possible chance for changing behavior quickly.
If the first round of feedback is ineffective, then shift your concern from him to other people, "Joe, I'm worried that some of our colleagues will overhear you and be really offended by that kind of talk. Could you try to avoid that in the future? I'd feel bad if someone were to be needlessly hurt or even feel harassed."
If these two levels of feedback are ineffective, there is no reason to see these communications as a failure or as having backfired in any way, because you have laid the ground work for feeling comfortable broaching the issue with management. If the behavior continues, now it is perfectly fair to escalate. In fact, it shouldn't hurt your relationship with the person because you tried to look out for him and keep him from getting in trouble. That is only to your credit.
He's going to probably find out it was you who raised the issue with management no matter what. In the end, using my suggested strategy keeps the whole issue professional and does a lot to remove you as "the bad guy"—no, you were just looking out for others, even if that is yourself in the third person.